题目

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。

Sample Input

1
10

Sample Output

6

Data Constraint

对于10%的数据, n<=1000

对于30%的数据, n<=10^10

对于60%的数据, n<=10^2000

对于100%的数据,T<=100,n<=10^25000。


分析

设pi为质数,m=p1e1·p2e2·p3^e3····。

我们首先来化简一下m/φ(m),容易得出m/φ(m)=(p1-1)(p2-1)(p3-1)···/p1·p2·p3····。

易证当p2>p1时,(p1-1)/p1>(p2-1)/p2,如果m取前k个质数的乘积,答案一定更优。答案就是最大的p1·p2·p3····。

如果边做边求p1·p2·p3····显然是不行的,所以先预处理p1·p2·p3····。大概60000以内的质数就可以,有6057个。为了缩短时间,高精度我压了11位,有点小恶心,事实上速度还是挺快的。

#include <cmath>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <queue>
const long long maxlongint=2147483647;
const long long mo=100000000000;
using namespace std;
long long b[6500][2500],zs[6500],t,n,m,a[2500];
char s[100000];
int times(long long x,long long y,long value)
{
long i,j,k,l;
for(i=1;i<=b[x][0];i++)
{
b[y][i]+=b[x][i]*value;
b[y][i+1]+=b[y][i]/mo;
b[y][i]%=mo;
}
b[y][0]=b[x][0];
if(b[y][b[y][0]+1]>0)
b[y][0]++;
}
int bj(long long a[2500],long long b[2500])
{
if(b[0]>a[0]) return true;
if(b[0]<a[0]) return false;
else
{
for(long long i=b[0];i>=1;i--)
{
if(b[i]>a[i]) return true;
if(b[i]<a[i]) return false;
}
}
return false;
}
int main()
{
scanf("%lld\n",&t);
long long i,j,k,l,x,y;
for(i=2;i<=60000;i++)
{
bool q=true;
for(j=2;j<=(long long)(sqrt(i));j++)
{
if(!(i%j)) q=false;
}
if(q)
{
zs[++zs[0]]=i;
}
}
b[0][0]=1;
b[0][1]=1;
for(i=1;i<=zs[0];i++)//预处理
{
times(i-1,i,zs[i]);
}
while(t--)
{
scanf("%s\n",s);
a[0]=0;
k=0;
int len=strlen(s);
l=1;
for(i=1;i<=len;i++)
{
k=k+(s[len-i]-48)*l;
l*=10;
if(l==mo)
{
a[++a[0]]=k;
l=1;
k=0;
}
}
if(k)
a[++a[0]]=k;
for(i=1;i<=zs[0];i++)//O(6057)求答案。如果还想快点,可以二分
{
if(bj(a,b[i]))
{
for(j=b[i-1][0];j>=1;j--)
{
if(j!=b[i-1][0])
printf("%011lld",b[i-1][j]);
else
printf("%lld",b[i-1][j]);
}
break;
}
}
printf("\n");
}
}

【Heaven Cow与God Bull】题解的更多相关文章

  1. 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 ...

  2. 「Poetize3」Heaven Cow与God Bull

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

  3. ACM-ICPC 2018 沈阳赛区网络预赛 Made In Heaven(K短路)题解

    思路:K短路裸题 代码: #include<queue> #include<cstring> #include<set> #include<map> # ...

  4. tyvj 1934 高精度

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

  5. bzoj AC倒序

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

  6. POJ 3167 Layout(差分约束)

    题面 Like everyone else, cows like to stand close to their friends when queuing for feed. FJ has N (2 ...

  7. 2018 ACM 网络选拔赛 沈阳赛区

    B. Call of Accepted #include <cstdio> #include <cstdlib> #include <cmath> #include ...

  8. BootStrap下拉框搜索功能

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

  9. POJ 2186 Popular cows(SCC 缩点)

    Every cow's dream is to become the most popular cow in the herd. In a herd of N (1 <= N <= 10, ...

随机推荐

  1. webpack bundle中parentJsonpFunction的作用

    parentJsonpFunction作用:使异步加载的模块在多个不同的bundle内同步. 假设有多入口文件 bundle1.js: bundl2.js: 在webpack打包后 加载流程: 1.b ...

  2. session 、cookie、token的区别(转)

    session  session的中文翻译是“会话”,当用户打开某个web应用时,便与web服务器产生一次session.服务器使用session把用户的信息临时保存在了服务器上,用户离开网站后ses ...

  3. 《React+Redux前端开发实战》笔记1:不涉及React项目构建的Hello World案例

    本小节实现一个不涉及项目构建的Hello World. [React的第一个Hello World网页] 源码地址:https://jsfiddle.net/allan91/2h1sf0ky/8/ & ...

  4. 11.metasploit辅助模块----基本Exp----ARP欺骗中间人MITM----WordPress破解

    metasploit辅助模块 信息收集 auxiliary scanners 使用metasploitable靶机 桥接 同一局域网 msfconsole nmap -sT 靶机IP nmap -sS ...

  5. clearfix:after 的用法

    想要清除浮动就要在父元素上 加上 clearfix:after .clearfix:after { <----在类名为“clearfix”的元素内最后面加入内容: content: " ...

  6. 第六周课程总结&实验报告

    一.实验目的 (1)掌握类的继承 (2)变量的继承和覆盖,方法的继承,重载和覆盖的实现: 二.实验的内容 (1)根据下面的要求实现圆类Circle. 1.圆类Circle的成员变量:radius表示圆 ...

  7. python深度学习培训概念整理

    对于公司组织的人工智能学习,每周日一天课程共计五周,已经上了三次,一天课程下来讲了两本书的知识.发现老师讲的速度太快,深度不够,而且其他公司学员有的没有接触过python知识,所以有必要自己花时间多看 ...

  8. python面试题--初级(一)

    一. Python 中有多少种运算符? 这类面试问题可以判断你的 Python 功底,可以举一些实例来回答这类问题. 在 Python 中我们有 7 中运算符: 算术运算符.关系 (比较) 运算符.赋 ...

  9. LINUX之启动流程

    (上图片转自一位高手所做) 启动第一步--加载BIOS当你打开计算机电源,计算机会首先加载BIOS信息,BIOS信息是如此的重要,以至于计算机必须在最开始就找到它.这是因为BIOS中包含了CPU的相关 ...

  10. 小a的轰炸游戏(差分,前缀和)

    题目传送门 题意: 给出一个n*m的矩形,然后有两个操作. 1操作,对一个给出的菱形,对菱形范围内的东西进行+1. 2操作,对一个上半菱形的区域,进行+1操作. 最后求矩形内各个数的异或和. 思路: ...