Description

__int64 ago,there's a heaven cow called sjy...
A god bull named wzc fell in love with her...
As an OI & MOer,wzc gave sjy a quesiton...

给定一个整数n,求一个整数m,满足m<=n,并且m/phi(m)的值最大。
注:phi(m)代表m的欧拉函数,即不大于m且与m互质的数的个数。

Input

第一行是一个整数T,表示该测试点有T组数据。
接下来T行,每行一个整数n,意义如上所述。

Output

输出一共T行,每行一个整数m。
若对于某个n,有不止一个满足条件的m,则输出最小的m。

贪心考虑,答案为质数的前缀积,筛出60000以内的质数,离线处理询问
高精度需要压位优化
#include<cstdio>
#include<cstring>
int ps[],pp=;
bool isnp[];
int T;
char str[];
int p10[]={,,,};
struct integer{
int x[],id,ed;
void read(){
scanf("%s",str);
int l=strlen(str)-;
for(int i=;i<=l;i++){
x[i>>]+=p10[i&]*(str[l-i]-'');
}
}
void print(){
int p=;
while(p&&!x[p])--p;
printf("%d",x[p]);
for(int i=p-;~i;--i)printf("%04d",x[i]);
putchar();
}
void operator*=(int a){
for(int i=;i<;i++)x[i]*=a;
for(int i=;i<;i++)x[i+]+=x[i]/,x[i]%=;
}
}q[],v,v1;
bool operator>(integer&a,integer&b){
for(int i=;~i;--i){
if(a.x[i]!=b.x[i])return a.x[i]>b.x[i];
}
return ;
}
int main(){
for(int i=;i<=;i++){
if(!isnp[i])ps[pp++]=i;
for(int j=;j<pp&&i*ps[j]<=;j++){
isnp[i*ps[j]]=;
if(i%ps[j]==)break;
}
}
scanf("%d",&T);
for(int i=;i<T;i++){
q[i].id=i;
q[i].read();
}
v.x[]=v1.x[]=;
for(int i=;i<pp;i++){
v*=ps[i];
for(int j=;j<T;j++)if(!q[j].ed&&v>q[j]){
q[j]=v1;
q[j].ed=;
}
v1=v;
}
for(int i=;i<T;i++){
for(int j=;j<T;j++)if(q[j].id==i){
q[j].print();
}
}
return ;
}

bzoj3034: Heaven Cow与God Bull的更多相关文章

  1. 【Heaven Cow与God Bull】题解

    题目 Description __int64 ago,there's a heaven cow called sjy... A god bull named wzc fell in love with ...

  2. 「Poetize3」Heaven Cow与God Bull

    描述 Description 给定一个整数n,求一个整数m,满足m<=n,并且m/phi(m)的值最大.注:phi(m)代表m的欧拉函数,即不大于m且与m互质的数的个数. 题解:m/phi(m) ...

  3. tyvj 1934 高精度

    「Poetize3」Heaven Cow与God Bull From wwwwodddd     背景 Background __int64 ago,there's a heaven cow call ...

  4. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  5. BootStrap下拉框搜索功能

    <!DOCTYPE html> <html> <head> <title>jQuery bootstrap-select可搜索多选下拉列表插件-www. ...

  6. Bull And Cows

    package cn.edu.xidian.sselab.hashtable; import java.util.HashMap;import java.util.Map;import java.ut ...

  7. POJ 3278 Catch That Cow(bfs)

    传送门 Catch That Cow Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 80273   Accepted: 25 ...

  8. 【BZOJ1623】 [Usaco2008 Open]Cow Cars 奶牛飞车 贪心

    SB贪心,一开始还想着用二分,看了眼黄学长的blog,发现自己SB了... 最小道路=已选取的奶牛/道路总数. #include <iostream> #include <cstdi ...

  9. HDU Cow Sorting (树状数组)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2838 Cow Sorting Problem Description Sherlock's N (1  ...

随机推荐

  1. HTTP 2.0 与 tomcat

    tomcat 支持http2.0吗? 首先,HTTP2.0协议一级公布,只是推广和各个中间件软件的适配需要时间. stackoverflow里“Tomcat support for HTTP/2.0? ...

  2. hdu4639 hehe ——斐波纳契数列,找规律

    link:http://acm.hdu.edu.cn/showproblem.php?pid=4639 refer to: http://blog.csdn.net/dongdongzhang_/ar ...

  3. sgu551 Preparing Problem

    题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=551 呵呵,题目读的没错,可惜理解错了..== #include <cstdi ...

  4. C陷阱与缺陷 1

    1,符号之间的空白被忽略 符号中间不能嵌入空白 2,词法分析中的贪心法 a---b 和 a-- -b相同 和 a- --b不同 1 a=b/*p //根据贪心法 /*被解释成 注释符,便不再往下读,直 ...

  5. SQL Server 合并表 union 和union all

    如果我们需要将两个select语句的结果作为一个整体显示出来,我们就需要用到union或者union all关键字.union(或称为联合)的作用是将多个结果合并在一起显示出来. union和unio ...

  6. openni和骨架追踪 rviz查看---34

    原创博客:转载请标明出处:http://www.cnblogs.com/zxouxuewei/ 1.安装深度相机的NITE. 首先下载NITE-Bin-Dev-Linux-x64-v1.5.2.23, ...

  7. TCP通讯程序设计---5

    这里主要包含客户机和服务器的编程. 一.编程模型函数化 使用函数说明:socket的理解 服务器: 创建socket使用函数----->socket 绑定地址使用函数------->bin ...

  8. spark新能优化之序列化

    概叙: 在任何分布式系统中,序列化都是扮演着一个重要的角色的.如果使用的序列化技术,在执行序列化操作的时候很慢,或者是序列化后的数据还是很大,那么会让分布式应用程序的性能下降很多.所以,进行Spark ...

  9. android开源项目---项目篇

    本文转载于:http://blog.csdn.net/likebamboo/article/details/19081151 主要介绍那些Android还不错的完整项目,目前包含的项目主要依据是项目有 ...

  10. debugging tools

    https://blogs.msdn.microsoft.com/debugdiag/ https://blogs.msdn.microsoft.com/debuggingtoolbox/2012/1 ...