lightoj欧拉函数打表(简单)

思路:这题只需要知道欧拉函数如何打表就行了。

点击题目链接

/*****************************************
Author      :Crazy_AC(JamesQi)
Time        :2015
File Name   :
*****************************************/
// #pragma comment(linker, "/STACK:1024000000,1024000000")
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;
#define MEM(a,b) memset(a,b,sizeof a)
typedef long long LL;
typedef unsigned long long ULL;
typedef pair ii;
const int inf = 1 << 30;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int maxn = 1e6 + 10;
int phi[maxn];
void phi_table(int n){
	for (int i = 2;i <= n;i++) phi[i] = 0;
		phi[1] = 1;
	for (int i = 2;i <= n;i++) if (!phi[i])
	for (int j = i;j <= n;j += i){
		if (!phi[j]) phi[j] = j;
		phi[j] = phi[j] / i * (i - 1);
	}
	// for (int i = 2;i <= n;i++)
		// phi[i] = max(phi[i],phi[i - 1]);
		// phi[i] = phi[i] > phi[i - 1]?phi[i]:phi[i - 1];
}
int a[maxn];
int main()
{	
	// freopen("in.txt","r",stdin);
	// freopen("out.txt","w",stdout);
	phi_table(maxn - 5);
	int T,n,x;
	int kase = 0;
	scanf("%d",&T);
	while(T--){
		scanf("%d",&n);
		for (int i = 0;i < n;i++)
			scanf("%d",&a[i]);
		sort(a,a + n);
		LL res = 0;
		for (int i = 0;i < n;i++){
			int k = a[i] + 1;
			// cout << "k = " << k << endl;
			while(phi[k] < a[i]) k++;
			res += k;
			// cout << "res = " << res << endl;
		}
		printf("Case %d: %lld Xukha\n",++kase,res);
	}
	return 0;
}


你可能感兴趣的:(数学-欧拉函数)