tyvj 1934 高精度
A god bull named wzc fell in love with her...
As an OI & MOer,wzc gave sjy a quesiton...
注:phi(m)代表m的欧拉函数,即不大于m且与m互质的数的个数。
接下来T行,每行一个整数n,意义如上所述。
若对于某个n,有不止一个满足条件的m,则输出最小的m。
对于30%的数据, n<=10^10
对于60%的数据, n<=10^2000
对于100%的数据,T<=100,n<=10^25000。
#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 高精度的更多相关文章
- TYVJ 矩阵取数 Label:高精度+dp
题目描述 帅帅经常跟同学玩一个矩阵取数游戏:对于一个给定的n*m的矩阵,矩阵中的每个元素aij均为非负整数.游戏规则如下: 1.每次取数时须从每行各取走一个元素,共n个.m次后取完矩阵所有元素: 2. ...
- NOIP 2005 等价表达式 (TYVJ P1060)
做题记录: 2016-08-10 23:35:09 背景 NOIP2005 提高组 第四道 描述 明明进了中学之后,学到了代数表达式.有一天,他碰到一个很麻烦的选择题.这个题目的题干中首先给出了一个代 ...
- CSharpGL(28)得到高精度可定制字形贴图的极简方法
CSharpGL(28)得到高精度可定制字形贴图的极简方法 回顾 以前我用SharpFont实现了解析TTF文件从而获取字形贴图的功能,并最终实现了用OpenGL渲染文字. 使用SharpFont,美 ...
- [BZOJ3223]Tyvj 1729 文艺平衡树
[BZOJ3223]Tyvj 1729 文艺平衡树 试题描述 您需要写一种数据结构(可参考题目标题),来维护一个有序数列,其中需要提供以下操作:翻转一个区间,例如原有序序列是5 4 3 2 1,翻转区 ...
- [BZOJ3224]Tyvj 1728 普通平衡树
[BZOJ3224]Tyvj 1728 普通平衡树 试题描述 您需要写一种数据结构(可参考题目标题),来维护一些数,其中需要提供以下操作:1. 插入x数2. 删除x数(若有多个相同的数,因只删除一个) ...
- 递推+高精度 UVA 10497 Sweet Child Makes Trouble(可爱的孩子惹麻烦)
题目链接 题意: n个物品全部乱序排列(都不在原来的位置)的方案数. 思路: dp[i]表示i个物品都乱序排序的方案数,所以状态转移方程.考虑i-1个物品乱序,放入第i个物品一定要和i-1个的其中一个 ...
- [Template]高精度模板
重新写一下高精度模板(不要问我为什么) 自认为代码风格比较漂亮(雾 如果有更好的写法欢迎赐教 封装结构体big B是压位用的进制,W是每位长度 size表示长度,d[]就是保存的数字,倒着保存,从1开 ...
- BZOJ3223: Tyvj 1729 文艺平衡树 [splay]
3223: Tyvj 1729 文艺平衡树 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 3595 Solved: 2029[Submit][Sta ...
- BZOJ 3224: Tyvj 1728 普通平衡树
3224: Tyvj 1728 普通平衡树 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 9629 Solved: 4091[Submit][Sta ...
随机推荐
- System Operations on AWS - Lab 5W - Managing Resources (Windows)
登陆到CommandHost实例,通过AWS CLI来管理各个资源 1. 通过Tags来管理资源 1.1 登陆到CommandHost实例 1.2 找出development实例 1.2.1 打开Po ...
- RedHat7/Windows7搭建JAVA开发环境(Eclipse)
RedHat7搭建JAVA开发环境 安装JAVA # yum install java 安装Tomcat # yum install tomcat 确认Tomcat版本 # tomcat versio ...
- .net单元测试——解除依赖
最近在看.net单元测试艺术,我也喜欢单元测试,这里写一下如何在测试中解除对象间的依赖. 假如有这样的一个需求,当用户登陆时,我需要对用户名和密码进行验证,然后再将用户名写入日志中. public c ...
- 多线程、Socket
多线程 线程.进程和应用程序域 进程:进程是一个操作系统上的概念,用来实现多任务并发执行,是资源分配的最小单元,各个进程是相互独立的,可以理解为执行当中的程序,在操作系统中一般用一个称为PCB的结 ...
- 用于做 Android 屏幕自适应的文章资源
Android Developer : (1) https://developer.android.com/training/multiscreen/index.html (2) https://de ...
- 排序算法(冒泡,选择,快速)Java 实现
冒泡 排序: public static void Bubblesort(int [] a) { for(int x=0;x<=a.length-1;x++) { for(int y=0;y&l ...
- css - a:hover变色问题
今天在帮我们学校做网站的时候,由于在css这里不是很擅长,过程中发现一个问题,a:hover的时候,字体的颜色不变.后来才发现将a和div的嵌套的问题, 我的css代码为: .left_box .lb ...
- 组策略彻底解决windows 2003 终端数
win2003的话可以从组策略修改: 组策略级别要高于终端服务配置,当启用组策略后终端服务配置中的相应选项会变成灰色不可修改 运行-gpedit.msc-计算机配置-管理模板-Windows ...
- Oracel JDBC URL 和 Driver 的获取
Driver 的获取 Driver Name: oracle.jdbc.driver.OracleDriver Oracel JDBC URL的获取: URL: jdbc:oracle:thi ...
- Object-C 类实现
这篇为Object-C添加方法的后续. 这里我们应该在类的实现(.m)文件中写 #import "Photo.h" @implementation Photo - (NSStrin ...