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 题意: 给定值,求满足欧拉值大于等于这个 ...
随机推荐
- shit leetcode edge testcases
shit leetcode edge testcases Merge Intervals try "use strict"; /** * * @author xgqfrms * @ ...
- js logical operation all in one
js logical operation all in one 逻辑运算 Logical AND (&&) Logical AND assignment (&&=) L ...
- how to tell a function arguments length in js
how to tell a function arguments length in js JavaScript函数不对参数值(参数)执行任何检查 https://www.w3schools.com/ ...
- React 16.x Roadmap
React 16.x Roadmap https://reactjs.org/blog/2018/11/27/react-16-roadmap.html https://reactjs.org/blo ...
- scroll tabs
scroll tabs https://github.com/NervJS/taro-ui/blob/dev/src/components/tabs/index.tsx https://github. ...
- github & code owners
github & code owners https://help.github.com/en/github/creating-cloning-and-archiving-repositori ...
- lua windows上使用vs编译Lua
video 下载lua源文件 还有种方法: 创建空项目,取名lua,导入lua源文件 将luac.c移除,然后编译lua.exe 将lua.c移除,添加luac.c然后编译lua.exe后重命名位lu ...
- Elasticsearch简介、倒排索引、文档基本操作、分词器
lucene.Solr.Elasticsearch 1.倒排序索引 2.Lucene是类库 3.solr基于lucene 4.ES基于lucene 一.Elasticsearch 核心术语 特点: 1 ...
- 从微信小程序到鸿蒙js开发【13】——list加载更多&回到顶部
鸿蒙入门指南,小白速来!从萌新到高手,怎样快速掌握鸿蒙开发?[课程入口] 目录: 1.list加载更多 2.list回到顶部 3.<从微信小程序到鸿蒙js开发>系列文章合集 1.list加 ...
- 开源OA办公平台功能介绍:应用市场-固定资产管理(一)功能设计
概述 应用市场-固定资产管理,是用来维护管理企业固定资产的一个功能.其整个功能包括对固定资产的台账信息.领用.调拨.借用.维修.盘点.报废等一整个生命周期的动态管理过程.力求客户安装就可以使用. 本应 ...