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 题意: 给定值,求满足欧拉值大于等于这个 ...
随机推荐
- 洛谷p2216 多次单调队列,扫描矩阵中的最大值减去最小值最的固定大小子矩阵
#include <iostream> #include <cstdio> #include <cstring> using namespace std; int ...
- linux 基础正则表达式练习
感谢鸟哥!!! 如果Linux能够直接连网络,使用以下命令还获取文件吧 wget http://linux.vbird.org/linux_basic/0330regularex/regular_ex ...
- 你不知道的 JS (系列丛书) - 第二版
你不知道的 JS (系列丛书) - 第二版 You Don't Know JS (book series) - 2nd Edition https://github.com/learning-js-b ...
- 如何在 GitHUb 上使用 gitbook 发布一本在线书籍
如何在 GitHUb 上使用 gitbook 发布一本在线书籍 ebook / pdf refs https://docs.gitbook.com/integrations/github xgqfrm ...
- Expose Loader & shit jquery
Expose Loader webpack https://github.com/xgqfrms/FEIQA/issues/31#issuecomment-418255126 require(&quo ...
- Koa & node.js
KOA https://github.com/koajs/koa https://koajs.com/ $ nvm install 7 # node.js 7 + $ nvm install 10 $ ...
- Dart & data type(static / dynamic)
Dart & data type(static / dynamic) Darts 飞镖 标枪 javelin/darts type https://dartpad.dartlang.org/ ...
- Online analog video interview
Online analog video interview 在线模拟视频面试 English 口语 https://www.pramp.com/#/ https://www.pramp.com/faq ...
- javascript IIFE in depth
javascript IIFE in depth function type 函数表达式 x = function (){ console.log(x); } ƒ (){ console.log(x) ...
- js form.onformData事件
在表单提交前修改数据,此事件在submit之后 f1.addEventListener("formdata", (e) => { e.formData.append(&quo ...