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

Re:我的RE疯了,那位高手帮忙看看?附代码

Posted by amazingjxq at 2008-06-02 16:06:41 on Problem 2407
In Reply To:我的RE疯了,那位高手帮忙看看?附代码 Posted by:liweishun2269 at 2008-05-31 16:10:37
> #include<iostream>
> #define M 1000000000
> using namespace std;
> int main()
> {
> 	int i,j,n;
> 	bool pr[M];
> 	double sum;
> 	for(i=0;i<M;i++)pr[i]=1;
> 	for(i=2;i*i<=M;i++)
> 	{
> 		if(pr[i-1])
> 		{
> 			for(j=i*i;j<=M;j+=i)pr[j-1]=0;
> 		}
> 	}
> 	while(1)
> 	{
> 		cin>>n;
> 		if(n==0)return 0;
> 		sum=n;
> 		for(i=2;i<=n/2;i++)
> 		{
> 			if(!pr[i-1])continue;
> 			if(n%i==0)sum*=1-1.0/i;
> 		}
> 		if(pr[n-1])sum*=1-1.0/n;
> 		cout<<sum<<endl;
> 	}
> }


for(j=i*i;j<=M;j+=i)pr[j-1]=0;
应该是j=2*i吧?

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