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 ouwenbo at 2015-05-31 09:34:57 on Problem 3090
In Reply To:不知道为啥用欧拉函数。斜率判重土方法胡搞过了。 Posted by:Liuzhaoliang at 2014-08-17 13:14:25
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int phi[1110],prime[1110],pr,n;
bool v[1110];
void getprime()
{
	int i,j,k;
	memset(v, true,sizeof(v));
	memset(phi,0,sizeof(phi));
	pr=0;
	for(i=2;i<=n;i++)
    {
		if(v[i]==true)
        {
			prime[++pr]=i;
			phi[i]=i-1;
		}
		for(j=1;(j<=pr)&&(i*prime[j]<=n);j++)
        {
			v[i*prime[j]]=false;
			if(i%prime[j]==0)
            {
				phi[i*prime[j]]=phi[i] * prime[j];
				break;
			}
			else phi[i*prime[j]]=phi[i] * (prime[j]-1);
		}
    }
}
int main()
{
	int t,i,j,ans=0;
	scanf("%d",&t);
	for(j=1;j<=t;j++)
	{
		ans=0;
		scanf("%d",&n);
		getprime();
		for(i=2;i<=n;i++)
		{
			ans+=phi[i];
		}
		ans=ans*2+3;
		printf("%d %d %d\n",j,n,ans);
	}
	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