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 chenxuan123456789 at 2012-09-22 23:41:43 on Problem 2478
Source Code

Problem: 2478  User: chenxuan123456789 
Memory: 12132K  Time: 313MS 
Language: GCC  Result: Accepted 

Source Code 
#include <stdio.h>
#include <string.h>
#define N 1000001
int prime[N];
__int64 ans[N];
int main()
{
	int i,j,k;
    prime[0] = 0;
	prime[1] = 0;
	for(i=2;i<N;i++)
		prime[i] = 1;
	for(i=2;i*i<=N;i++)
	{
		if(prime[i])
		{
			for(j=i*i;j<=N;j+=i)
				prime[j] = 0;
		}
	}
	for(i=1;i<=N;i++)
	{
		ans[i] = i;
	}
	for(i=2;i<=N;i++)
	{
		if(prime[i])
		{
			for(j=i;j<N;j+=i)
				ans[j]=(ans[j]/i)*(i-1);
		}
	}
	for(i=3;i<=N;i++)
	ans[i] += ans[i-1];
	while(scanf("%d",&k)!=EOF&&k)
	{
		printf("%I64d\n",ans[k]);
	}
	return 1;
}

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