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 |
兄弟,帮我看看为什么超了#include <iostream> using namespace std; int main() { int n; while(cin>>n) { if(n==0) break; int a,b; cin>>a>>b; int x=0,p1,p2,t,i=2; int s[1000001]; memset(s,-1,sizeof(s)); p1=(a*((x*x)%n)%n+b)%n; s[0]=p1; p2=(a*((p1*p1)%n)%n+b)%n; s[1]=p2; while(i<1000000) { p1=p2; p2=(a*((p1*p1)%n)%n+b)%n; s[i]=p2; ++i; if(i>=n) break; } int j,k,num; for(j=0;j<i;++j) for(k=j+1;k<i;++k) if(s[j]==s[k]) { num=k-j; break; } cout<<n-num<<endl; } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator