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:你贴一下程序

Posted by comerpass at 2005-07-15 01:38:16 on Problem 2480
In Reply To:你贴一下程序 Posted by:frkstyc at 2005-07-15 01:37:38
#include<iostream>
#include<vector>
#include<math.h>
using namespace std;
#define max_v 100000

__int64 p[50000];
vector<int>pr;

__int64 ph(int m)
{
	int x=m;
if(m<50&&p[m]) return p[m];
	__int64 r=1;
	for(int i=0;i<pr.size();i++){
		if(m%pr[i]==0){
			r*=pr[i]-1;m/=pr[i];
			while(m%pr[i]==0){m/=pr[i];r*=pr[i];}
		}
		if(m<50&&p[m]){r*=p[m]; break;}
	}
if(x<50)p[x]=r;
return r;
}

int gcd(int a,int b)
{
 if(b==0)return a;
 return gcd(b,a%b);
}

int main()
{	
	int i;
	for(i=2;i<50000;i++)
	if(!p[i])
	{
		pr.push_back(i);
		int x=i+i;
		while(x<50000){p[x]=1;x+=i;}
	}
	int x;
	memset(p,0,sizeof(p));
	p[1]=1;
	__int64 f;
	 x=1;
	while(cin>>x) {
		f=0;
		for(int i=1;i<=sqrt(x);i++){
			if(x%i==0){
				f+=(x/i)*ph(i);
				if(i*i!=x)f+=i*ph(x/i);
			
			}
	
		}
		printf("%I64d\n",f);
		

	}


}

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