「Poetize3」Heaven Cow与God Bull
 
 
背景 Background
__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...

 

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

 

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

 

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

 

 
样例输入 SampleInput [复制数据]
1
10
 
 
样例输出 SampleOutput [复制数据]
6
 
 
数据范围和注释 Hint
对于10%的数据, n<=1000
对于30%的数据, n<=10^10
对于60%的数据, n<=10^2000
对于100%的数据,T<=100,n<=10^25000。

 
 
本题只是用来存一个高精类模板。
另外复习一下,phi(x)=x × (1-1/p1)×(1-1/p2) × ... × (1-1/pn)
本题是求 maximize {1/ [(1-1/p1)×(1-1/p2) × ... × (1-1/pn)] }
即 minimize{   (1-1/p1)×(1-1/p2) × ... × (1-1/pn)  }
然后就是水题了。
只是编的时候TLE了很久,原因是素数表开小了。
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<fstream>
using namespace std;
#define MAXL 10000
#define VAL1 10000
#define MAXN 20100
class number//四位
{
public:
number()
{
clear();
}
bool is_odd()
{
return numb[]%==;
}
bool is_even()
{
return numb[]%==;
}
void lsh_bin()
{
int i;
for (i=topn;i>;i--)
{
if (numb[i]%==)
{
numb[i-]+=VAL1;
}
numb[i]/=;
}
numb[]/=;
while (topn&&!numb[topn])topn--;
}
bool equal_to(int x)
{
if (topn==)
{
return x==numb[];
}
if (topn==)
{
return x==numb[]+numb[]*VAL1;
}
return false;
}
int size()
{
return topn;
}
int length()
{
int x=numb[topn];
int ret=;
while (x)
{
ret++;
x/=;
}
int y=;
x=VAL1;
while (x)
{
y++;
x/=;
}
y--;
ret+=topn*y;
return ret;
}
void operator =(int x)//{{{
{
int now=;
clear();
numb[now]=x;
while (numb[now]>=VAL1)
{
numb[now+]+=numb[now]/VAL1;
numb[now]%=VAL1;
now++;
if (now>topn)topn=now;
}
}//}}}
void operator =(number num)
{
topn=num.topn;
memcpy((this->numb),num.numb,sizeof(num.numb[])*(topn+));
}
void operator +=(number &num)//{{{
{
int i;
topn=max(topn,num.topn);
for (i=;i<=topn;i++)
{
numb[i]+=num.numb[i];;
if (numb[i]>=VAL1)
{
numb[i+]+=numb[i]/VAL1;
numb[i]%=VAL1;
}
}
while (numb[topn+])
{
topn++;
numb[topn+]+=numb[topn]/VAL1;
numb[topn]%=VAL1;
}
}//}}}
void operator +=(int x)//{{{
{
int now=;
if (topn==-)topn=;
numb[now]+=x;
while (numb[now]>=VAL1)
{
numb[now+]+=numb[now]/VAL1;
numb[now]%=VAL1;
now++;
if (now>topn)topn=now;
}
}//}}}
void operator *=(int x)//{{{
{
int i;
for (i=;i<=topn;i++)
{
numb[i]*=x;
}
for (i=;i<=topn;i++)
{
if (numb[i]>=VAL1)
{
numb[i+]+=numb[i]/VAL1;
numb[i]%=VAL1;
}
}
while (numb[topn+])
{
topn++;
numb[topn+]+=numb[topn]/VAL1;
numb[topn]%=VAL1;
}
}//}}}
void operator -=(number &num)//{{{
{
if (*this<num)throw "Error!\n->void operator -=(number &num)\n";
int i;
for (i=;i<=topn;i++)
{
numb[i]-=num.numb[i];
}
for (i=;i<=topn;i++)
{
while (numb[i]<)
{
numb[i]+=VAL1;
numb[i+]--;
}
}
while (topn&&!numb[topn])topn--;
}//}}}
void operator --(int)//{{{
{
if (topn==&&numb[]==)throw "Error!\n->void operator --(int)\n";
int now=;
numb[now]--;
while (numb[now]<)
{
numb[now+]--;
numb[now]+=VAL1;
}
while (topn&&!numb[topn])topn--;
}//}}}
private:
int numb[MAXL];
int topn;
void clear()
{
topn=;
memset(numb,,sizeof(numb)); }
friend bool operator <(number num1,number num2);
friend bool operator <=(number num1,number num2);
friend bool operator ==(number num1,number num2);
friend ostream& operator <<(ostream &out,number &num);
friend istream& operator >>(istream &in,number &num);
friend number operator *(number &num1,number &num2);
friend number operator *(number num,int x);
friend number operator +(number num1,number num2);
//a=a+b远没有a+=b快
};
bool operator <(number num1,number num2)//{{{
{
if (num1.topn!=num2.topn)
{
return num1.topn<num2.topn;
}
int i;
for (i=num1.topn;i>=;i--)
{
if (num1.numb[i]!=num2.numb[i])
{
return num1.numb[i]<num2.numb[i];
}
}
return false;
}//}}}
bool operator <=(number num1,number num2)//{{{
{
if (num1.topn!=num2.topn)
{
return num1.topn<num2.topn;
}
int i;
for (i=num1.topn;i>=;i--)
{
if (num1.numb[i]!=num2.numb[i])
{
return num1.numb[i]<num2.numb[i];
}
}
return true;
}//}}}
bool operator ==(number num1,number num2)//{{{
{
if (num1.topn!=num2.topn)return false;
for (int i=;i<=num1.topn;i++)
{
if (num1.numb[i]!=num2.numb[i])return false;
}
return true;
}//}}}
ostream& operator <<(ostream &out,number &num)//{{{
{
int i;
out<<num.numb[num.topn];
for (i=num.topn-;i>=;i--)
{
//压六位时
// if (num.numb[i]<100000)out<<"0";
// if (num.numb[i]<10000)out<<"0";
if (num.numb[i]<)out<<"";
if (num.numb[i]<)out<<"";
if (num.numb[i]<)out<<"";
out<<num.numb[i];
}
return out;
}//}}}
istream& operator >>(istream &in,number &num)//{{{
{
string str;
in>>str;
int i;
num.clear();
for (i=(int)str.length()-,num.topn=;i>=;i-=,num.topn++)
{
if (i-<str.length())
{
num.numb[num.topn]=(str[i]-'')+*(str[i-]-'')+*(str[i-]-'')+*(str[i-]-'');
}else
{
if (i-<str.length())num.numb[num.topn]+=*(str[i-]-'');
if (i-<str.length())num.numb[num.topn]+=*(str[i-]-'');
if (i <str.length())num.numb[num.topn]+=(str[i]-'');
}
}
num.topn--;
return in;
}//}}}
number operator *(number num,int x)//{{{
{
number ret;
ret=num;
ret*=x;
return ret;
}//}}}
number operator +(number num1,number num2)//{{{
{
number ret;
ret=num1;
ret+=num2;
return ret;
}//}}}
number x,y,z;
bool pflag[];
int prime[],topp=-;
void init()
{
int i,j;
for (i=;;i++)
{
if (!pflag[i])
{
prime[++topp]=i;
if (topp==)break;
}
for (j=;j<=topp&&prime[j]*i<;j++)
{
pflag[prime[j]*i]=;
}
}
}
struct aaa
{
number qq;
int id;
}qur[];
bool cmp1(aaa a1,aaa a2)
{
return a1.qq<a2.qq;
}
bool cmp2(aaa a1,aaa a2)
{
return a1.id<a2.id;
} bool sved[];
int main()
{
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
int n,i;
init();
cin>>n;
for (i=;i<n;i++)
{
cin>>qur[i].qq;
qur[i].id=i;
}
z=;
/* for (i=0;i<6500;i++)z*=prime[i];
cout<<z.length()<<endl;;
for (i=0;i<500000;i++)
{
y=z;
} */
sort(qur,&qur[n],cmp1);
y=;
int now=;
for(i=;;i++)
{
z=y*prime[i];
while (qur[now].qq<z)
{
qur[now].qq=y;
now++;
if (now==n)break;
}
if (now==n)break;
y=z;
}
sort(qur,&qur[n],cmp2);
for (i=;i<n;i++)
{
cout<<qur[i].qq<<endl;
}
}

tyvj 1934 高精度的更多相关文章

  1. TYVJ 矩阵取数 Label:高精度+dp

    题目描述 帅帅经常跟同学玩一个矩阵取数游戏:对于一个给定的n*m的矩阵,矩阵中的每个元素aij均为非负整数.游戏规则如下: 1.每次取数时须从每行各取走一个元素,共n个.m次后取完矩阵所有元素: 2. ...

  2. NOIP 2005 等价表达式 (TYVJ P1060)

    做题记录: 2016-08-10 23:35:09 背景 NOIP2005 提高组 第四道 描述 明明进了中学之后,学到了代数表达式.有一天,他碰到一个很麻烦的选择题.这个题目的题干中首先给出了一个代 ...

  3. CSharpGL(28)得到高精度可定制字形贴图的极简方法

    CSharpGL(28)得到高精度可定制字形贴图的极简方法 回顾 以前我用SharpFont实现了解析TTF文件从而获取字形贴图的功能,并最终实现了用OpenGL渲染文字. 使用SharpFont,美 ...

  4. [BZOJ3223]Tyvj 1729 文艺平衡树

    [BZOJ3223]Tyvj 1729 文艺平衡树 试题描述 您需要写一种数据结构(可参考题目标题),来维护一个有序数列,其中需要提供以下操作:翻转一个区间,例如原有序序列是5 4 3 2 1,翻转区 ...

  5. [BZOJ3224]Tyvj 1728 普通平衡树

    [BZOJ3224]Tyvj 1728 普通平衡树 试题描述 您需要写一种数据结构(可参考题目标题),来维护一些数,其中需要提供以下操作:1. 插入x数2. 删除x数(若有多个相同的数,因只删除一个) ...

  6. 递推+高精度 UVA 10497 Sweet Child Makes Trouble(可爱的孩子惹麻烦)

    题目链接 题意: n个物品全部乱序排列(都不在原来的位置)的方案数. 思路: dp[i]表示i个物品都乱序排序的方案数,所以状态转移方程.考虑i-1个物品乱序,放入第i个物品一定要和i-1个的其中一个 ...

  7. [Template]高精度模板

    重新写一下高精度模板(不要问我为什么) 自认为代码风格比较漂亮(雾 如果有更好的写法欢迎赐教 封装结构体big B是压位用的进制,W是每位长度 size表示长度,d[]就是保存的数字,倒着保存,从1开 ...

  8. BZOJ3223: Tyvj 1729 文艺平衡树 [splay]

    3223: Tyvj 1729 文艺平衡树 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 3595  Solved: 2029[Submit][Sta ...

  9. BZOJ 3224: Tyvj 1728 普通平衡树

    3224: Tyvj 1728 普通平衡树 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 9629  Solved: 4091[Submit][Sta ...

随机推荐

  1. ios9中 UIStackView的使用

    ios9中 UIStackView的使用 by 伍雪颖 UIStackView能够垂直或水平排布多个subview, 自己主动为每一个subview创建和加入Auto Layout constrain ...

  2. NuGet的使用和服务搭建

    问题的由来 最近部门,在开发的时候遇到一个问题,现在有项目A B C三个项目,项目B和C分别提供了组件库由项目A直接引用.那么每次开打项目A获取最新后,同时还得打开项目B C获取最新然后编译一次.抛开 ...

  3. [Node.js] Exporting Modules in Node

    In this lesson, you will learn the difference between the exports statement and module.exports. Two ...

  4. windows修改mysql默认字符集不成功

    今天下午弄了半天,终于把mysql的默认字符集弄成了, 按照网上的说法,什么修改mysql下面的my.ini文件,把参数设置成utf-8,我反复操作,结果都是不成功,后来我把mysql5.0卸载了,网 ...

  5. Android开发之显示进度对话框

    一般有两种对话框,一个是普通的简单的please wait对话框,另一种是创建显示操作进度(如下载状态)的对话框. 第一种普通的效果图如下: 第一种普通的实现代码: public void onCli ...

  6. Java使用jackson问题解决

    Java使用jackson问题解决 >>>>>>>>>>>>>>>>>>>>&g ...

  7. Python开发实战教程(8)-向网页提交获取数据

    来这里找志同道合的小伙伴!↑↑↑ Python应用现在如火如荼,应用范围很广.因其效率高开发迅速的优势,快速进入编程语言排行榜前几名.本系列文章致力于可以全面系统的介绍Python语言开发知识和相关知 ...

  8. Android pulltorefresh引用遇到的一个问题

    今天在使用pulltorefresh插件的时候遇到了一个让人头疼的问题,在Eclipse中导入要用到的library项目,然后新建一个项目引入Library,显示的是引入成功,如图 而且project ...

  9. DataDictionaryTool 一款生成数据库字典工具支持mysql和oracle

    因为常常查看mysql数据结构,频繁操作.很不爽,于是想把数据表制作成数据字典,于是网上搜的一款工具 DataDictionaryTool ,最终制作成功,分享给大家! 1,此工具需要安装jre ,简 ...

  10. 基础之 window-self-top-opener

    今天我都在怀疑,很多项目还用不用iframe这个框架做页面布局. 如果你有兴趣想告诉我,请给我留言. 一. 说明 注:这里top和window.top等价,window是可以省略的,有得情况下不允许省 ...