Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

兄弟,帮我看看为什么超了

Posted by jlnu123 at 2008-11-02 21:31:14 on Problem 2939
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator