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 题意: 给定值,求满足欧拉值大于等于这个 ...
随机推荐
- vue v-on-clickaway
vue v-on-clickaway Custom directive 自定义指令 https://stackoverflow.com/questions/36170425/detect-click- ...
- React Native for Windows + macOS
React Native for Windows + macOS React Native 0.63 https://aka.ms/ReactNative https://microsoft.gith ...
- npm & package.json & directories & files
npm & package.json & directories & files package.json https://docs.npmjs.com/files/packa ...
- open an iOS simulator from the terminal
open an iOS simulator from the terminal # simulator $ open -a Simulator flutter https://flutter.dev/ ...
- javascript disable scroll event
javascript disable scroll event Document: scroll event https://developer.mozilla.org/en-US/docs/Web/ ...
- flutter 让app跟随系统的theme
首先你需要在"MaterialApp"设置两套theme MaterialApp( theme: myTheme, // light darkTheme: ThemeData.da ...
- 【函数分享】每日PHP函数分享(2021-2-19)
array_diff_uassoc - 用用户提供的回调函数做索引检查来计算数组的差集 说明 array_diff_uassoc ( array $array1 , array $array2 , a ...
- 关于Python 编码的一点认识
在计算机中,所有数据的存储.运算以及传输都必须是二进制数字,因为计算机只认识0和1. 当一个人把一份数据传给另一个人时,计算机传递的是其实是二进制数字,但这些数字需要被还原为原始信息. 这个工作当然是 ...
- HTTP 协议中的并发限制及队首阻塞问题
本文转载自HTTP 协议中的并发限制及队首阻塞问题 串行连接 HTTP/0.9 和早期的 HTTP/1.0 协议对 HTTP 请求处理是串行化的.假如一个页面包含 3 个样式文件,同属于一个协议.域名 ...
- 2021-2-22:请你说下 CAP 理论并举例
CAP CAP 理论是分布式系统中的一个老生常谈的理论了,最早由 Eric Brewer 在一个讲座中提出.在这个讲座中,在传统 ACID 理论以及当时比较流行但是比较抽象的的设计指导理论 BASE ...