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 fwmm at 2011-01-30 23:04:33 on Problem 2478
#include<iostream>
using namespace std;
int eun[1000005]={0};
int ans[1000005]={0};
int eular(int m)
{
	int ans=m;
	int n=m;
	for(int i=2;i*i<=m;i++)
	{
			if(n%i==0)
			{
				ans=ans-ans/i;
				while(n%i==0)
					n/=i;
			}
	}
	if(n!=1)
	ans=ans-ans/n;
	return ans;
}
int main()
{
	int n,i,sum;
	ans[1]=0;
	for(i=2;i<=100000;i++)
	{
		eun[i]=eular(i);
		ans[i]=ans[i-1]+eun[i];
	}
	while(scanf("%d",&n)&&n)
	{
		
		if(n==0)
		{
			break;
		}
		printf("%d\n",ans[n]);
	}
	return 0;
}

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