基础数论 1001 LightOJ 1370
2016-07-21 20:45
316 查看
题意:
给一个n个数,假设有数x
->求每个xphi(n)>=x最小的n的和
思路:
预处理一下phi(i)
然后先求出最小的Tab(i)代表phi(n)==i的最小的n
因为有些phi取不到,所以需要取后边的,随便写写就好了
给一个n个数,假设有数x
->求每个xphi(n)>=x最小的n的和
思路:
预处理一下phi(i)
然后先求出最小的Tab(i)代表phi(n)==i的最小的n
因为有些phi取不到,所以需要取后边的,随便写写就好了
#include<stdio.h> #include<string.h> #include<iostream> #include<algorithm> #include<math.h> #include<queue> #include<stack> #include<string> #include<vector> #include<map> #include<set> using namespace std; #define lowbit(x) (x&(-x)) typedef long long LL; const int maxn = 100005; const int inf=(1<<28)-1; #define maxp 2000100 bool notprime[maxp]; int phi[maxp]; void get_phi() { notprime[1]=true; for(int i=1;i<maxp;++i) phi[i]=1; for(int i=2;i<maxp;++i) if(!notprime[i]) { phi[i]*=i-1; for(int j=i+i;j<maxp;j+=i) { notprime[j]=true; int n=j/i; phi[j]*=i-1; while(n%i==0) { n/=i; phi[j]*=i; } } } } int Tab[maxp]; int main() { get_phi(); memset(Tab,-1,sizeof(Tab)); for(int i=2;i<maxp;++i) if(Tab[phi[i]]==-1) Tab[phi[i]]=i; int flag=-1; for(int i=maxp-1;i>=1;--i) if(Tab[i]!=-1) { flag=i; break; } for(int i=flag-1;i>=1;--i) { if(Tab[i]==-1) Tab[i]=Tab[i+1]; else if(Tab[i]>Tab[i+1]) Tab[i]=Tab[i+1]; } int T,Case=0; scanf("%d",&T); while(T--) { int n; LL Ans=0; scanf("%d",&n); for(int i=0;i<n;++i) { int x; scanf("%d",&x); Ans+=Tab[x]; } printf("Case %d: %lld Xukha\n",++Case,Ans); } return 0; }
相关文章推荐
- fineUI ueditor(可能别的editor也有)配置注意事项
- Guacamole之本地安装Guacamole(二)
- Codeforces 580 B-----二分
- The Text Splitting
- bulb
- 广义径向基神经网络
- ERROR Cannot determine the location of the VS Common Tools Folder
- IP分片
- c语言实现字符串的分割
- 安装CentOS 7.2操作系统
- 关于AsyncHttpClient使用
- 计算机启动过程(转)
- Android混合开发 java和js交互
- 数据结构-串的堆分配存储
- BZOJ1207 [HNOI2004]打鼹鼠
- Splash Screen 加载窗体 [not finished]
- (3)通过声明的方式创建ApplicationContext对象
- 关于bootcmd与bootargs初解
- UVA-156 Ananagrams
- 2016暑期集训---周赛(水题)