LightOJ 1370Bi-shoe and Phi-shoe(欧拉函数)
来源:互联网 发布:胖子丁丁小吗 知乎 编辑:程序博客网 时间:2024/05/17 02:21
题目大意:首先你需要明白欧拉函数是什么:欧拉函数指的是n以内与n互质的所有数的个数。
假如n是质数,很明显,它的欧拉函数等于n-1;
题目给你n个x,然后你要求出n个数的和,这n个数对应的欧拉函数大于x
这道题我就是这么乱搞,然后过了。我也说不清楚为什么。
反正总结一句话就是 欧拉函数大于等于x的那个数就是x+1之后的第一个质数
打出100w内的素数表。
然后找到x+1之后的第一个素数就ok了。
代码当中还有打出100W以内所有数的欧拉函数的方法,比较慢,但也可以AC
#define _CRT_SECURE_NO_WARNINGS#include<cstdio>#include<cstring>#include<algorithm>#include<iostream>using namespace std;bool prim[1100000];void init(){memset(prim, 0, sizeof prim);prim[1] = 1;for (int i = 2; i < 1100000;i++)if (!prim[i])for (int j = i + i; j < 1100000; j += i)prim[j] = 1;}double a[1100000];void init2(){for (int i = 1; i < 1100000; i++){a[i] = i;int mid = i;for (int j = 2; j*j <= mid;j++)if (mid%j == 0){a[i] *= (j - 1);while (mid%j == 0)mid /= j;a[i] /= j;}}}int main(){int t;cin >> t;init2();int icase = 1;while (t--){int n;scanf("%d", &n);int x;long long sum = 0;while (n--){scanf("%d", &x);int x2 = x+1;while (a[x2]<x)x2++;sum += x2;}printf("Case %d: %lld Xukha\n", icase++,sum);}}
0 0
- LightOJ 1370 Bi-shoe and Phi-shoe 欧拉函数
- LightOJ 1370- Bi-shoe and Phi-shoe (欧拉函数)
- LightOJ 1370Bi-shoe and Phi-shoe(欧拉函数)
- LightOJ 1370-Bi-shoe and Phi-shoe(欧拉函数)
- 【LightOJ】1370 - Bi-shoe and Phi-shoe(欧拉函数,素数打表)
- LightOJ 1370 Bi-shoe and Phi-shoe(欧拉函数)
- LightOJ 1370 Bi-shoe and Phi-shoe (欧拉函数)
- Lightoj 1370 Bi-shoe and Phi-shoe(欧拉函数)
- lightoj1370 - Bi-shoe and Phi-shoe(欧拉函数)
- Bi-shoe and Phi-shoe(欧拉函数变形)
- Bi-shoe and Phi-shoe (欧拉函数)
- LightOJ Bi-shoe and Phi-shoe 1370【欧拉函数+素数打表】
- LightOJ 1370 Bi-shoe and Phi-shoe (欧拉函数+二分)
- LightOJ 1370 Bi-shoe and Phi-shoe【欧拉函数 && 质数】
- lightoj 1370 Bi-shoe and Phi-shoe 【欧拉函数应用】
- lightoj-1370 Bi-shoe and Phi-shoe( 欧拉筛 求 欧拉函数)
- lightOj 1370 Bi-shoe and Phi-shoe
- LightOJ-1370 Bi-shoe and Phi-shoe
- Xamarin介绍和Windows环境搭建
- 安装第二个JDK,发现系统还是调用第一个JDK
- MySQL数据库如何修改root用户的密码
- MySQL类型介绍以及适用范围
- 打印三角形
- LightOJ 1370Bi-shoe and Phi-shoe(欧拉函数)
- 自己想要的到底是什么?what do you want?
- (2)iOS用UICollectionView实现Gallery效果
- 源码免杀系列教程
- 单例模式
- ANSI/ISO_C POSIX GLIBC WIN32 种种C标准的概念区分
- UVa694 - The Collatz Sequence(模拟)
- 参数化查询速度慢
- Objective C基础(四)---Category、Extension、Protocol