|
|
back to boardwhy i got wrong 4? #include<stdio.h> long n,a,k; void work () { long i,na,x; if (n<316227) x=2*n; else x=316227; for (i=x;i>=1;i--) { na=2*n+i-i*i; if (((na%(2*i))==0)&&(na>0)) { na=na/(2*i); a=na; k=i; break; } } } int main () { scanf ("%ld",&n); work (); printf ("%ld %ld",a,k); return 0; } Re: why i got wrong 4? Test: 10^9 Your program result: 4811 148480 My AC program result: 26263 25600 Re: why i got wrong 4? #include<iostream> #include<stdio.h> using namespace std; __int64 n,a,k; void work () { __int64 i,na,x; if (n<316227) x=2*n; else x=316227; for (i=x;i>=1;i--) { na=2*n+i-i*i; if (((na%(2*i))==0)&&(na>0)) { na=na/(2*i); a=na; k=i; break; } } } int main () { cin>>n; work (); cout<<a<<" "<<k; return 0; } #include<stdio.h> long n,a,k; void work () { long i,na,x; if (n<316227) x=2*n; else x=316227; for (i=x;i>=1;i--) { na=2*n+i-i*i; if (((na%(2*i))==0)&&(na>0)) { na=na/(2*i); a=na; k=i; break; } } } int main () { scanf ("%ld",&n); work (); printf ("%ld %ld",a,k); return 0; } Re: why i got wrong 4? Posted by plague 27 Dec 2007 22:10 My program result: 1243 640 for n= 10^6 Edited by author 27.12.2007 22:11 |
|
|