1. 程式人生 > >LightOJ 1370 Bi-shoe and Phi-shoe(歐拉函數)

LightOJ 1370 Bi-shoe and Phi-shoe(歐拉函數)

cas 數字 url col div ase style while gin

http://lightoj.com/login_main.php?url=volume_showproblem.php?problem=1370

題意:

給一些數Ai(第 i 個數),Ai這些數代表的是某個數歐拉函數的值,我們要求出數 Ni 的歐拉函數值不小於Ai。而我們要求的就是這些 Ni 這些數字的和sum,而且我們想要sum最小,求出sum最小多少。

思路:
素數P的歐拉函數值為P-1。

所以對於一個給出的數,我們去尋找大於它的第一個素數即可。

 1 #include<iostream>
 2 #include<algorithm>
 3 #include<cstring>
 4
#include<cstdio> 5 #include<vector> 6 #include<queue> 7 #include<cmath> 8 #include<map> 9 #include<stack> 10 using namespace std; 11 12 const int maxn=1e6+5; 13 14 int n; 15 int vis[maxn]; 16 17 void get_primes() 18 { 19 int m=sqrt(maxn+0.5
); 20 for(int i=2;i<=m;i++) 21 { 22 if(!vis[i]) 23 { 24 for(int j=i*i;j<=maxn;j+=i) 25 vis[j]=1; 26 } 27 } 28 } 29 30 int main() 31 { 32 //freopen("D:\\input.txt","r",stdin); 33 int T; 34 int kase=0; 35 get_primes();
36 scanf("%d",&T); 37 while(T--) 38 { 39 long long sum=0; 40 scanf("%d",&n); 41 for(int i=0;i<n;i++) 42 { 43 int x; 44 scanf("%d",&x); 45 for(int k=x+1;;k++) 46 { 47 if(!vis[k]) 48 { 49 sum+=k; 50 break; 51 } 52 } 53 } 54 printf("Case %d: %lld Xukha\n",++kase,sum); 55 } 56 57 return 0; 58 }

LightOJ 1370 Bi-shoe and Phi-shoe(歐拉函數)