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 题意: 给定值,求满足欧拉值大于等于这个 ...
随机推荐
- Google PageSpeed Insights : 网站性能优化检测工具
1 1 https://developers.google.com/speed/pagespeed/insights/ PageSpeed Insights 使您的网页在所有设备上都能快速加载. 分析 ...
- MongoDB Up and Going
# MongoDB Up and Going https://ide.c9.io/xgqfrms/mongodb # MongoDB 教程 https://www.runoob.com/mongodb ...
- js useful skills blogs
js useful skills blogs blogs https://davidwalsh.name/tutorials/javascript https://www.ruanyifeng.com ...
- Linux & terminal color & command line color
Linux & terminal color & command line color how to change Linux terminal color https://askub ...
- Chrome & console.log & color & js
Chrome & console.log & color & js console.log & color // OK log(`%cchat_list =\n%c${ ...
- css grid layout in practice
css grid layout in practice https://caniuse.com/#search=grid subgrid https://caniuse.com/#search=cal ...
- Flutter: provider 使用小部件的小部件构建的依赖注入系统
文档 dependencies: provider: import 'package:dart_printf/dart_printf.dart'; import 'package:flutter/ma ...
- vue的filter用法,检索内容
var app5 = new Vue({ el: '#app5', data: { shoppingList: [ "Milk", "Donuts", &quo ...
- Python元组拆包捡到8倍镜快准狠
元组拆包 元组是不可变列表,列表是通过索引取值的,元组也是: tuple_test = (1, 2, 3) a = tuple_test[0] b = tuple_test[1] c = tuple_ ...
- react虚拟dom