|
|
back to boardAnswer is 1 1 But if A=1,P=1 A+P-1=1, so A+(A+P-1)=2 NOT 1?Am I wrong? 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. 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; } 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. Thanks a lot,I passed WA,but now TLE #9.This algo is too slow :( try to manipulate this : N = P*(2A + (P-1))/2 N = input A & P = output loop P to find A Right answer for 1 is 0 2 not 1 0 !!! right answer is 1 1 , because 1=1+(1-1) 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. |
|
|