|
|
вернуться в форумWhat is the output for N=1 ? Re: What is the output for N=1 ? Послано rohit 23 май 2008 13:40 Answer is 1 1 Re: What is the output for N=1 ? But if A=1,P=1 A+P-1=1, so A+(A+P-1)=2 NOT 1?Am I wrong? Re: What is the output for N=1 ? Послано rohit 23 май 2008 18:38 The sequence is an arithmetic progression upto p terms. So, when n=1, only 1 term is required ie p=1. Hope you could understand. Re: What is the output for N=1 ? This is my code. It gets WA#7,but I cant find my mistake.Could you help,pls? #include<iostream.h> int main() { int n,i,j,s; cin>>n; if(n==1) { cout<<"1 1"; return 0; } if(n==2) { cout<<"2 1"; return 0; } for(i=1;i<=n/2;i++) { s=i; for(j=i+1;s<n;j++) s+=j; if(s==n) { cout<<i<<" "<<j-i; return 0; } } cout<<n/2<<" "<<1; return 0; } No subject Послано rohit 25 май 2008 01:53 Maximum value of a is n not n/2. Your program gives wrong answer for n=4. Your output is 2 1 while correct one is 4 1. TLE #9 Thanks a lot,I passed WA,but now TLE #9.This algo is too slow :( Re: TLE #9 Послано rohit 26 май 2008 03:37 Solve it mathematically. Re: TLE #9 Послано indra 31 май 2008 23:35 try to manipulate this : N = P*(2A + (P-1))/2 N = input A & P = output loop P to find A Re: OK, AC now. Thanks . Right answer for 1 is 0 2 not 1 0 !!! Re: OK, AC now. Thanks . right answer is 1 1 , because 1=1+(1-1) Re: No subject ok i think this should be 2 2 Maximum value of a is n not n/2. Your program gives wrong answer for n=4. Your output is 2 1 while correct one is 4 1. |
|
|