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 ...
随机推荐
- JS基础知识(作用域/垃圾管理)
1.js没有块级作用域 if (true) { var color = “blue”; } alert(color); //”blue” for (var i=0; i < 10; i++){ ...
- UI学习笔记---第二天
程序的执行流程 一.自定义视图 自定义UILebal-UITextField视图 ⾃定义视图:系统标准UI之外,⾃己组合而出的新的视图. 实际开发中,我们还需⾃定义视图.积累⾃己的代码库.⽅便开发. ...
- SQLITE SUBSTR
insert into t_user values(4,'u1234567890'); sqlite> select substr(username,1,1) from t_user where ...
- 浅谈jQuery中setInterval()方法
定义和用法: setInterval() 方法可按照指定的周期(以毫秒计)来调用函数或计算表达式. setInterval() 方法会不停地调用函数,直到 clearInterval() 被调用或窗口 ...
- 软件工程课程作业(二)--四则运算2改进版(c++)
题目要求: 1.避免题目重复 2.可定制(数量/打印方式) 3.可以控制下列参数 (1)是否有乘除法 (2)是否有括号 (3)数值范围 (4)加减有无负数 (5)除法有无余数 关键设计思想: oper ...
- Fresco好案例
http://www.open-open.com/lib/view/open1436094840774.html
- linux 网络协议分析---3
本章节主要介绍linxu网络模型.以及常用的网络协议分析以太网协议.IP协议.TCP协议.UDP协议 一.网络模型 TCP/IP分层模型的四个协议层分别完成以下的功能: 第一层 网络接口层 网络接口层 ...
- 越狱Season 1-Episode 17: J-Cat
Season 1, Episode 17: J-Cat -Pope: Hey, that's looking good. 嗨,看起来真棒 You're making some real progres ...
- JS 排序算法
冒泡排序: 核心思想:从第一个开始遍历数组,遍历完成后,让最小的值放在第一位:然后从第二个开始遍历数组,遍历完成后将最小值放在第二位:以此类推,所有位的数组遍历完成后就排序完成. var arr = ...
- linux下的符号链接和硬链接
一 Linux下链接文件的作用 Linux特别注重用户的权限,而链接文件的作用也正体现了这个方面.对源文件的位置进行了隐藏,用户只对链接文件操作. 二 链接文件的区别 链接文件分为硬链接文件和软 ...