LightOJ 1370 Bi-shoe and Phi-shoe
/*
LightOJ 1370 Bi-shoe and Phi-shoe
http://lightoj.com/login_main.php?url=volume_showproblem.php?problem=1370
数论 欧拉函数
坑点是答案会爆int!!!!
*/
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <iostream>
#include <map>
#include <set>
//#define test
using namespace std;
const int Nmax=1e6+5e5;//Nmax一定要大于1e6否则会找不到答案
int phi[Nmax];
int prime[Nmax];
int is_prime[Nmax];
int prime_cnt;
void get()
{
phi[]=;
for(int i=;i<Nmax;i++)
is_prime[i]=;
for(long long i=;i<Nmax;i++)
{
if(is_prime[i])
{
prime[++prime_cnt]=i;
phi[i]=i-;
}
for(int j=;j<=prime_cnt;j++)
{
if(i*prime[j]>=Nmax)
break;
is_prime[i*prime[j]]=;
if(i%prime[j]==)
{
phi[i*prime[j]]=phi[i]*prime[j];
break;
}
else
phi[i*prime[j]]=phi[i]*(prime[j]-);
}
}
}
int main()
{
#ifdef test
#endif
get();
phi[]=;//此题要求phi[1]=0;
//for(int i=1;i<Nmax;i++)
//{
//num[i].id=i;
//num[i].val=phi[i];
//}
//sort(num+1,num+Nmax);
//for(int i=1;i<=40;i++)
//{
//printf("phi[%d]:%d\n",i,phi[i]);
//}
int t,n;
scanf("%d",&t);
for(int ttt=;ttt<=t;ttt++)
{
scanf("%d",&n);
long long ans=0LL;//此题一大坑点,ans会爆int
int a;
for(int i=;i<=n;i++)
{
scanf("%d",&a);
for(int j=a+;j<Nmax;j++)//强力减枝!
{
if(phi[j]>=a)
{
ans+=1LL*j;
break;
}
}
}
printf("Case %d: %lld Xukha\n",ttt,ans);
}
return ;
}
LightOJ 1370 Bi-shoe and Phi-shoe的更多相关文章
- 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 ...
- 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 题意: 给定值,求满足欧拉值大于等于这个 ...
- LightOJ 1370 Bi-shoe and Phi-shoe 欧拉函数+线段树
分析:对于每个数,找到欧拉函数值大于它的,且标号最小的,预处理欧拉函数,然后按值建线段树就可以了 #include <iostream> #include <stdio.h> ...
- LightOJ - 1370
Bi-shoe and Phi-shoe Time Limit: 2000MS Memory Limit: 32768KB 64bit IO Format: %lld & %llu S ...
- LightOJ - 1370 Bi-shoe and Phi-shoe (欧拉函数打表)
题意:给N个数,求对每个数ai都满足最小的phi[x]>=ai的x之和. 分析:先预处理出每个数的欧拉函数值phi[x].对于每个数ai对应的最小x值,既可以二分逼近求出,也可以预处理打表求. ...
- 欧拉函数 || LightOJ 1370 Bi-shoe and Phi-shoe
给出x,求最小的y使y的欧拉函数大于等于x *解法:i).求出1e6之内的数的欧拉函数,遍历找 ii).求比x大的第一个质数——因为每个质数n的欧拉函数都是n-1 wa一次是因 ...
- 【LightOJ - 1370】Bi-shoe and Phi-shoe
Bi-shoe and Phi-shoe Descriptions: 给出一些数字,对于每个数字找到一个欧拉函数值大于等于这个数的数,求找到的所有数的最小和. Input 输入以整数T(≤100)开始 ...
随机推荐
- bag of words in c++
#include <iostream> #include <vector> #include <cstddef> #include <string> # ...
- MySQL max_connections 总是 214 。不能设大了? max_connections = 214
MySQL max_connections 总是 214 .不能设大了? centos7 mariadb 修改 max_connections 总是214 It was indeed limits s ...
- 常见的几种异常类型Exception
转自:https://blog.csdn.net/niceworkgogogo/article/details/71746208 算数异常类:ArithmeticExecption 空指针异常类型:N ...
- 基于docker的tomcat服务化
tomcat作为web容器被广泛应用,但作者所在的公司restful接口特别多,每个接口都需要一个tomcat来启动,为了配置隔离,一般都会把tomcat安装文件复制多遍,分别把war包部署在对应的w ...
- 拼接sql ()
SELECT ID,FORMNAME,NODENAME,SEQUENCE, NAME, STATE, NOWTIMES, WORK.FQREALNAME||'('||FQDEPT.FULLN ...
- asp.net core 2.0 Json结果的格式
asp.net core 2.0 默认返回的结果格式是Json, 并使用json.net对结果默认做了camel case的转化(大概可理解为首字母小写). 这一点与老.net web api 不一样 ...
- linux 查看 cpu
如何获得CPU的详细信息: linux命令:cat /proc/cpuinfo 用命令判断几个物理CPU,几个核等: 逻辑CPU个数:# cat /proc/cpuinfo | grep " ...
- linux 怎么在后台添加运行脚本,即使关机也可以用
nohup ma.php >guangxindai.log 2>&1 & 或者 nohup ma.php & 在shell中,文件描述符通常是:STDIN标准输入, ...
- POJ 1584 计算几何
思路: 求一遍凸包 用三角形面积(叉积求一下)/边长 求出来高,跟半径比一比 坑点:凸包上三点共线 //By SiriusRen #include <cmath> #include < ...
- [转帖]c++ 面试整理
1. 继承方式 public 父类的访问级别不变 protected 父类的public成员在派生类编程protected,其余的不变 private 父类的所有成员变成pr ...