Bi-shoe and Phi-shoe LightOJ - 1370(数论+素数筛)
题目链接:https://vjudge.net/problem/LightOJ-1370
题意:给你N个欧拉函数值,找出每一个大于等于该欧拉函数值的数,并且要求相加和最小。
题解:因为素数i的欧拉函数值等于i-1,所以我们只要找出大于等于i+1的素数即可。

1 #include<iostream>
2 #include<algorithm>
3 #include<vector>
4 #include<cstring>
5 #include<cstdio>
6 using namespace std;
7 #define mem(s,n) memset(s,n,sizeof s);
8 typedef long long ll;
9 const int maxn=1e6+100;
10 const int Inf=0x7f7f7f7f;
11 int prim[maxn];
12 //这里只需要判断是不是素数即可不用记录。
13 void prime()
14 {
15 mem(prim,0);
16 prim[0]=prim[1]=1;
17 for(int i=2;i<maxn;i++)
18 {
19 if(prim[i]==0)
20 {
21 for(int j=i*2;j<maxn;j+=i)
22 {
23 prim[j]=1;
24 }
25 }
26 }
27 }
28 int main()
29 {
30 int t,n;
31 prime();
32 //for(int i=0;i<maxn;i++) cout<<i<<" "<<prim[i]<<endl;
33 scanf("%d",&t);
34 int k=0;
35 while(t--)
36 {
37 scanf("%d",&n);
38 ll sum=0;
39 for(int i=1;i<=n;i++)
40 {
41 int p;
42 scanf("%d",&p);
43 p++;
44 int j;
45 for( j=p;j<maxn;j++)
46 {
47 if(prim[j]==0) {break;}
48 }
49 sum+=j;
50 }
51 printf("Case %d: %lld Xukha\n",++k,sum);
52 }
53 return 0;
54 }
代码详情
Bi-shoe and Phi-shoe LightOJ - 1370(数论+素数筛)的更多相关文章
- LightOJ-1259 Goldbach`s Conjecture 数论 素数筛
题目链接:https://cn.vjudge.net/problem/LightOJ-1259 题意 给一个整数n,问有多少对素数a和b,使得a+b=n 思路 素数筛 埃氏筛O(nloglogn),这 ...
- LightOJ 1370 Bi-shoe and Phi-shoe
/* LightOJ 1370 Bi-shoe and Phi-shoe http://lightoj.com/login_main.php?url=volume_showproblem.php?pr ...
- lightoj 1370 欧拉函数
A - Bi-shoe and Phi-shoe Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & % ...
- LightOJ 1370 - Bi-shoe and Phi-shoe (欧拉函数思想)
http://lightoj.com/volume_showproblem.php?problem=1370 Bi-shoe and Phi-shoe Time Limit:2000MS Me ...
- ACM数论-素数
ACM数论——素数 素数定义: 质数(prime number)又称素数,有无限个.质数定义为在大于1的自然数中,除了1和它本身以外不再有其他因数,这样的数称为质数.例 子:2.3.5.7.11.1 ...
- 数论-欧拉函数-LightOJ - 1370
我是知道φ(n)=n-1,n为质数 的,然后给的样例在纸上一算,嗯,好像是找往上最近的质数就行了,而且有些合数的欧拉函数值还会比比它小一点的质数的欧拉函数值要小,所以坚定了往上找最近的质数的决心—— ...
- LightOJ 1370 Bi-shoe and Phi-shoe 数论
题目大意:f(x)=n 代表1-x中与x互质的数字的个数.给出n个数字a[i],要求f(x)=a[i],求x的和. 思路:每个素数x 有x-1个不大于x的互质数.则f(x)=a[i],若a[i]+1为 ...
- Lightoj 1370 素数打表 +二分
1370 - Bi-shoe and Phi-shoe PDF (English) Statistics Time Limit: 2 second(s) Memory Limit: 32 MB ...
- LightOJ 1370 Bi-shoe and Phi-shoe【欧拉函数 && 质数】
题目链接: http://lightoj.com/login_main.php?url=volume_showproblem.php?problem=1370 题意: 给定值,求满足欧拉值大于等于这个 ...
随机推荐
- Springboot如何启用文件上传功能
网上的文章在写 "springboot文件上传" 时,都让你加上模版引擎,我只想说,我用不上,加模版引擎,你是觉得我脑子坏了,还是觉得我拿不动刀了. springboot如何启用文 ...
- tfrecords转np.array
import tensorflow as tf import numpy as np from keras.utils import to_categorical import sys def tfr ...
- JavaScript string repeat methods All In One
JavaScript string repeat methods All In One There are many ways in the ES-Next ways repeat ES2015 / ...
- CURL & Weather
CURL & Weather https://wttr.in/ $ curl wttr.in https://github.com/chubin/wttr.in refs http://www ...
- iPhone 12 导入通讯录排序 Bug
iPhone 12 导入通讯录排序 Bug iOS iOS 通讯录排序问题 Huawei OK solution iOS 切换中英文,修复排序通讯录 bug Awesome iOS Contacts ...
- Expose Loader & shit jquery
Expose Loader webpack https://github.com/xgqfrms/FEIQA/issues/31#issuecomment-418255126 require(&quo ...
- SVG 与 Canvas 对比
SVG 与 Canvas 对比 技术选型 SVG vs Canvas 应用场景 性能 GPU 加速 XML 数据存储 Canvas 2D Canvas 3D WebGL / OpenGL ES thr ...
- HTMLMediaElement.srcObject & URL.createObjectURL & HTMLMediaElement.src
HTMLMediaElement.srcObject & URL.createObjectURL & HTMLMediaElement.src Uncaught TypeError: ...
- GitHub & GitHub Package Registry
GitHub & GitHub Package Registry npm https://github.blog/2019-05-10-introducing-github-package-r ...
- import script module
import script module .mjs <script type="module"> import {addTextToBody} from './util ...