bzoj3034: Heaven Cow与God Bull
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。
#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的更多相关文章
- 【Heaven Cow与God Bull】题解
题目 Description __int64 ago,there's a heaven cow called sjy... A god bull named wzc fell in love with ...
- 「Poetize3」Heaven Cow与God Bull
描述 Description 给定一个整数n,求一个整数m,满足m<=n,并且m/phi(m)的值最大.注:phi(m)代表m的欧拉函数,即不大于m且与m互质的数的个数. 题解:m/phi(m) ...
- tyvj 1934 高精度
「Poetize3」Heaven Cow与God Bull From wwwwodddd 背景 Background __int64 ago,there's a heaven cow call ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- BootStrap下拉框搜索功能
<!DOCTYPE html> <html> <head> <title>jQuery bootstrap-select可搜索多选下拉列表插件-www. ...
- Bull And Cows
package cn.edu.xidian.sselab.hashtable; import java.util.HashMap;import java.util.Map;import java.ut ...
- POJ 3278 Catch That Cow(bfs)
传送门 Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 80273 Accepted: 25 ...
- 【BZOJ1623】 [Usaco2008 Open]Cow Cars 奶牛飞车 贪心
SB贪心,一开始还想着用二分,看了眼黄学长的blog,发现自己SB了... 最小道路=已选取的奶牛/道路总数. #include <iostream> #include <cstdi ...
- HDU Cow Sorting (树状数组)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2838 Cow Sorting Problem Description Sherlock's N (1 ...
随机推荐
- jquery easyui datebox 时间控件默认显示当前日期的实现方法
jquery easyui datebox 时间控件默认显示当前日期的实现方法 直接class easyui-datebox后添加一个value="true"就可以
- 修饰符(static、final、abstract)第二篇
二.Final 核心:一旦创建,不可修改 可修饰:(创建即终态) 1.类:被修饰后,将不能被继承 2.方法:被修饰后,将不能被覆写 3.属性:被创建,不可修改,且必须赋值(赋值的两种形式): 1.直接 ...
- js如何把字符串转换成json数据的方法
js如何把字符串转换成json数据的方法 function strtojson(str){ var json = eval('(' + str + ')'); return json; } 方法二 f ...
- c#部分---好题--顺便练练“类的知识”
练习:判断邮箱格式是否正确 //1.有且只能有一个@ //2.不能以@开头 //3.@之后至少有一个. //4.@和.不能靠在一起 //5.不能以.结尾
- Maven项目中找不到maven dependencies library
一般是,workspace中的.classpath文件中有内容丢失造成 在 <classpathentry kind="con" path="org.eclipse ...
- 转 用 AXIOM 促进 XML 处理
转自:http://www.ibm.com/developerworks/cn/xml/x-axiom/ AXIOM 还不是另一种对象模型.它有着明确的设计目标:大幅提升 Apache 下一代 SOA ...
- 《Java程序设计》第3周学习总结
学号20145220<Java程序设计>第3周学习总结 教材学习内容总结 使用jave撰写程序几乎都在使用对象(Object),要产生对象必须先定义类(Class),类是对象的设计图,对象 ...
- 救援行动(save) (BFS)
时间限制: 1 Sec 内存限制: 64 MB提交: 42 解决: 9[提交][状态][讨论版] 题目描述 Angel被人抓住关在一个迷宫了!迷宫的长.宽均不超过200,迷宫中有不可以越过的墙以及 ...
- FZU-2216 The Longest Straight (二分枚举)
题目大意:给n个0~m之间的数,如果是0,那么0可以变为任意的一个1~m之间的一个数.从中选出若干个数,使构成一个连续的序列.问能构成的最长序列的长度为多少? 题目分析:枚举连续序列的起点,二分枚举二 ...
- Qt消息机制和事件(二)
三,事件过滤器 有时候,对象需要查看.甚至要拦截发送到另外对象的事件.例如,对话框可能想要拦截按键事件,不让别的组件接收到:或者要修改回车键的默认处理. 通过前面的章节,我们已经知道,Qt 创建了QE ...