|
|
Since N is as big as 10000 the solution for N = 10000 exceeds unsigned long so you should use big numbers (put the numbers in arrays and then do the operations on the arrays) https://www.infoarena.ro/lucrul-cu-nr-marivar n:integer; s:real; begin read(n); s:=n*((n+1 )/2)*(n+2); write(s); end. округли 'round' У тебя 12.0 не пройдет,а надо 12 Edited by author 26.11.2019 11:33 Как удалить тему? Edited by author 26.11.2019 11:32 Edited by author 26.11.2019 11:32 var n:integer; s:real; begin read(n); s:=(n+2)*((n+1)*n)/2; write(s); end. Use "longint" and not "integer" or "real". 1000 => 501501000 500 => 62875500 333 => 18629685 1 => 3 3 => 30 4 => 60 and use long long =) I know i am stupid but help me to understand this formula! n*(n+1)/2*(n+2) Edited by author 02.11.2013 03:06 Edited by author 02.11.2013 03:12 This formula is equivalent to the this sum: sum(i=0 -> N) sum(j=i -> N) (i + j) Edited by author 27.11.2015 01:21 He guys if you can't come up with any formula...pre-computation will do the job.I could not come up with any formula so I used precomputation and AC in 0.015 sec.Good luck :) i cant find 12 distinct combinations if N = 2... i can only think of: 0-0 0-1 0-2 1-1 1-2 2-2 That are only 6 combinations... what did i miss? 0-0 (0+0=0) 0-1 (0+1=1) 0-2 (0+2=2) 1-1 (1+1=2) 1-2 (1+2=3) 2-2 (2+2=4) | 0+1+2+2+3+4=12 got it? but how does the formula N*(N+1)/2*(N+2) comes ? pls explain... :) The problem does not ask you to count the # of distinct dominoes in a set, it asks you to count the # of dots on a complete set. import java.util.Scanner; public class AcmTimusRu { public static void main(String[] args) { Scanner s = new Scanner(System.in); int n = s.nextInt(); System.out.println(n * (n + 1) * (n + 2) / 2); } } Hey, guys, i've did it! No need to be so smarty, just use long long :) Formula is obvious and it already somewhere in this forum, so you can find it USE LONG LONG! 1000 => 501501000 500 => 62875500 333 => 18629685 1 => 3 3 => 30 4 => 60 But Wa#5 Edited by author 28.10.2006 17:09 The same with me: WA#5 can anybody tell me why Just use int64 instead of longint; My solution is very short and I also get WA5, my answers are the same as those posted, can anyone give some hint ? I got Accepted using BrutForce!!! Already solved this problem, read the hint below :) Edited by author 30.10.2006 21:20 Yes , me , too . WA#5 but AC now , you should change "int n" into "long long n" . Yup, 10x pal, you saved me from reading again and again this task and to wonder where I was wrong :) Who can find my mistake? [code deleted] it passes all my tests, but it can't pass 5 Edited by moderator 29.12.2006 09:16 This is my formula for (int i = 0; i <= n; ++i) res += (i + n) * (n - i + 1) / 2 + i * (n - i + 1); This one is mine: n*-~n*-~-~n>>1 Have fun! Thanks for the advice. Could you tell me what brings this change? n=10000 fits in an int, doesn't it? Ha! Got accepted only with __int64 and not with long long... my djgpp returns a compilation error on such a line... could anybody explain me what should that be? Edited by author 10.11.2006 01:16 Edited by author 02.03.2008 12:54 Edited by author 02.03.2008 12:53 I didn't get accepted until I switched printf() with cout. I used %lld for the format of printf and still it got WA. Same formula, same code, just that i used cout/cin and I got AC. I used printf with "%llu" and got AC the first attempt. u - unsigned d - digit (signed) In paskal when n=10000 you can not write this expression n*(n+1)*(n+2)/2 in some variables it is very long and big number so in C++ it is very easy just write(here is my AC program): #include <cstdlib> #include <iostream> using namespace std; int main(int argc, char *argv[]) { long long n; cin>>n; cout<<n*(n+1)*(n+2)/2<<endl; system("PAUSE"); return EXIT_SUCCESS; } Edited by author 27.04.2008 17:47 In Pascal you can use Int64 why is it true? can u explain me please?) Answer for n is n*(n+1)/2*(n+2) For example if n=2 then answer is 2*3/2*4=12 The formula is correct and is easily proven by solving the sums: sum(i=0 -> N) sum(j=0 -> N) (i + j) Edited by author 03.02.2012 17:25 Actually the inner sum needs to start at i, not at zero. Starting at 0 counts non-double dominoes twice. My program only read integer and write integer (ready formula). Why it works 0.015 sec? Edited by author 11.06.2009 00:15 Because this is the minimum measurement time possible on the current version of the judge. Edited by author 21.02.2009 18:37 Maybe because the answer is a very large number, more than INT_MAX. int sum; // WA 5 long long sum; // Accepted (int64) 100 => 515100 1000 => 501501000 9999 => 499999995000 7779 => 235455472110 1234 => 941825820 Good luck! Thanks. This tests very much help to me All codes listed below works good on my computer (and they give correct answers), but when submitting I get: Code #1: --------------------------------------------------------- #include<stdio.h> #include<iostream.h> int main() { long long n; cin>>n; long long wynik; wynik=(n*(n+1)*(n+2))/2; cout<<wynik<<endl; return 0; } ---------------------------------------------------------- Compilation error Code #2: removed iostream.h and replaced cin and cout with scanf("%lld",%n); and printf("%lld\n",wynik); WA on test 5 Code #3: same as #2, but with printf("%0.lf\n, (double)wynik); instead WA on test 1 ----------------------------------------------------------- All those programs work and give correct results on my computer. What's wrong here? Please help. For The First Code : Add using namespace std; for using cin & cout. Here my solution: --- end. I can not understand that incorrectly. Help somebody))))))) Edited by author 08.11.2009 03:46 The answer for 10000 is as large as 500150010000 The answer for 10000 is as large as 500150010000 What type to use? The biggest it longInt. 500150010000 does not enter there. |
|
|