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)开始 ...
随机推荐
- nginx初相识
在本机上下载了一个nginx,版本为1.14.0. 安装: 对于安装比较简单,下载后解压到指定目录,目录结构如下 启动: 最简单的直接双击nginx.exe,有黑窗一闪而过,不要怀疑,看一下logs的 ...
- codevs2503失恋28天......(背包dp)
503 失恋28天-缝补礼物 时间限制: 1 s 空间限制: 32000 KB 题目等级 : 黄金 Gold 题目描述 Description 话说上回他给女孩送了n件礼物,由于是廉价的所以 ...
- Linux 下 Solr的搭建与使用(建议jdk1.8以上)
官方表示solr5之后的版本不再提供对第三方容器的支持(不提供war包了). “旧式”solr.xml格式不再支持,核心必须使用core.properties文件定义. 使用第三方容器的需要自己手动修 ...
- Android 显示意图和隐式意图的区别
意图在android的应用开发中是很重要的,明白了意图的作用和使用后,对开发会有很大帮助.如果没有把意图搞懂,以后开发应用会感觉缺些什么. 意图的作用: 1.激活组件 ...
- css为什么叫层叠样式表
------------------------------------------------------------------------------------ 层叠就是浏览器对多个样式来源进 ...
- linux如何更改yum源
更改linux yum源方法:第一步:进入yum配置文件目录:cd /etc/yum.repos.d/第二步:备份配置文件(如果后续出现了问题就可以恢复):mv CentOS-Base.repo Ce ...
- Elasticsearch之Hadoop插件的安装(图文详解)
这个Hadoop插件的安装是非常重要. Hadoop插件安装 在es的安装目录下 bin/plugin install elasticsearch/elasticsearch-repository-h ...
- Spring Cloud (11) Hystrix-监控聚合监控
上一篇利用Hystrix Dashboard去监控断路器的Hystrix command,当我们有很多服务的时候,就需要聚合所有服务的Hystrix Dashboard数据了,这就需要Hystrix ...
- debounce还是throttle(去抖和节流)
debounce 去抖 我的理解很简单,比方说window.onscroll会疯狂触发handler,此时给它一个debounce(handler, delayTime). 就是不管你延时时间内触发了 ...
- JavaScript中的 函数splice() 的使用。
大二接触JavaScript初期,学习函数中有一道题: 定义一个2个参数的函数.第1个参数是一个数组,第2个参数是需要删除的元素.函数功能,在第1个实参数组中查找第2个实参提供的值,找到则删除该元素( ...