Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
我用递推的思路,一切OK,怎么提交错了?错那了,希望有人帮我指正!#include<iostream> #include<math.h> using namespace std; long sum=0; long long fun(long a,long b) { if(a==0)return 1; if(a==1)return 1; if(b==0)return 1; if(b==1)return sum%9901; long long s=sum%9901; for(long i=2;i<=b;++i) s=(s+(sum-1)+(a-1)*(s-1))%9901;//递归思路是:fun(a,b)=( f(a,b-1)+(sum-1)*a^(b-1) )%9901 return s; //由于递归慢,反递推就得到这个,可不知道怎么错了 } int main() { long a,b,i; cin>>a>>b; if(a==0)sum=0; else if(a==1)sum=1; else if(a==2)sum=3; else if(a==3)sum=4; else { for(i=1;i<(long)sqrt(1.0*a);++i) { if(a%i==0) sum+=i+a/i; } if(i==(long)sqrt(1.0*a)) sum+=(long)sqrt(1.0*a); } cout<<fun(a,b)<<endl; getchar(); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator