「Poetize3」Heaven Cow与God Bull
注:phi(m)代表m的欧拉函数,即不大于m且与m互质的数的个数。
m/phi(m) 很容易化成 连积(p/(p-1)) p|m
所以就很简单了,将最小的质数乘起来,直到>n,输出前一个。
因为保证最小所以只乘一次,因为p/(p-1)单调减,所以从小的开始选。
高精度写错搞了好久,然后有卡了几次时才过了
代码:
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<string>
#define inf 1000000000
#define maxn 100000
#define maxm 500+100
#define eps 1e-10
#define ll long long
#define pa pair<int,int>
#define for0(i,n) for(int i=0;i<=(n);i++)
#define for1(i,n) for(int i=1;i<=(n);i++)
#define for2(i,x,y) for(int i=(x);i<=(y);i++)
#define for3(i,x,y) for(int i=(x);i>=(y);i--)
#define mod 10
using namespace std;
inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=*x+ch-'';ch=getchar();}
return x*f;
}
int n,m,tot,p[maxn];
bool v[maxn];
char ch[maxn];
class bigg{
public:
int num[maxn],len;
bigg()
{
memset(num,,sizeof(num));
len=;
}
inline bigg operator =(const bigg &b)
{
memset(num,,sizeof(num));
len=b.len;
for1(i,len)num[i]=b.num[i];
return(*this);
}
inline bigg operator =(int b)
{
memset(num,,sizeof(num));
len=;
while(b){num[++len]=b%mod;b/=mod;}
return(*this);
}
inline bigg operator *(int b)
{
for1(i,len)num[i]*=b;
for1(i,len)
{
num[i+]+=num[i]/mod;
num[i]%=mod;
if(num[len+])len++;
}
return(*this);
}
inline bool operator <(const bigg&b)
{
if(len!=b.len)return len<b.len;
for3(i,len,)if(num[i]!=b.num[i])return num[i]<b.num[i];
return ;
}
inline void print()
{
printf("%d",num[len]);
for3(i,len-,)printf("%d",num[i]);printf("\n");
}
};
bigg a[],b,c[];
int rk[];
bool cmp(int x,int y){return a[x]<a[y];}
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
for2(i,,maxn)
{
if(!v[i])p[++tot]=i;
for1(j,tot)
{
int k=p[j]*i;
if(k>maxn)break;
v[k]=;
if(i%p[j]==)break;
}
}
n=read();
for1(i,n)
{
scanf("%s",ch+);
a[i].len=strlen(ch+);
for1(j,a[i].len)a[i].num[j]=ch[a[i].len+-j]-'';
rk[i]=i;
}
sort(rk+,rk+n+,cmp);
int j=;
b=j;
//for1(i,100)b=b*p[i],b.print();
for1(i,n)
{
c[rk[i]]=c[rk[i-]];
while(b<a[rk[i]])c[rk[i]]=b,b=b*p[j++];
//b.print();
}
//for1(i,n)a[rk[i]].print(),c[rk[i]].print();
for1(i,n)c[i].print();
return ;
}
不知道每组询问暴力求会不会T,我为了保险拍了个序233
UPD:这个程序交到bz也T了。。。TAT
无奈看了lyd的程序,居然预处理压了8位!
orzz
憋了1h+终于写出来了,二分+预处理。。。
代码:
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<string>
#define inf 1000000000
#define maxn 100000
#define maxm 500+100
#define eps 1e-10
#define ll long long
#define pa pair<int,int>
#define for0(i,n) for(int i=0;i<=(n);i++)
#define for1(i,n) for(int i=1;i<=(n);i++)
#define for2(i,x,y) for(int i=(x);i<=(y);i++)
#define for3(i,x,y) for(int i=(x);i>=(y);i--)
#define mod 100000000
using namespace std;
inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=*x+ch-'';ch=getchar();}
return x*f;
}
int n,m,tot,p[maxn];
bool v[maxn];
char s[maxn];
class bigg{
public:
int num[],len;
bigg()
{
memset(num,,sizeof(num));
len=;
}
inline bigg operator =(const bigg &b)
{
memset(num,,sizeof(num));
len=b.len;
for1(i,len)num[i]=b.num[i];
return(*this);
}
inline bigg operator =(int b)
{
memset(num,,sizeof(num));
len=;
while(b){num[++len]=b%mod;b/=mod;}
return(*this);
}
inline bigg operator *(int b)
{
ll x=;
for1(i,len)
{
x+=(ll)num[i]*b;
num[i]=x%mod;
x/=mod;
}
if(x)num[++len]=x;
return(*this);
}
inline bool operator <(const bigg&b)
{
if(len!=b.len)return len<b.len;
for3(i,len,)if(num[i]!=b.num[i])return num[i]<b.num[i];
return ;
}
inline void print()
{
printf("%d",num[len]);
for3(i,len-,)printf("%08d",num[i]);printf("\n");
}
};
bigg a,b[];
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
for2(i,,maxn)
{
if(!v[i])p[++tot]=i;
for1(j,tot)
{
int k=p[j]*i;
if(k>maxn)break;
v[k]=;
if(i%p[j]==)break;
}
}
b[]=;
for1(i,)b[i]=b[i-],b[i]=b[i]*p[i];
int cs=read();
while(cs--)
{
memset(s,,sizeof(s));
scanf("%s",s);
n=strlen(s);
reverse(s,s+n);
for0(i,n-)s[i]-='';
a.len=(n+)/;
for0(i,a.len-)
a.num[i+]=s[i*]+*s[i*+]+*s[i*+]+*s[i*+]+*(s[i*+]+*s[i*+]+*s[i*+]+*s[i*+]);
int l=,r=,mid;
while(l<=r)
{
mid=(l+r)>>;
if(b[mid]<a)l=mid+;else r=mid-;
}
b[r].print();
}
return ;
}
UPD:
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<string>
#define inf 1000000000
#define maxn 100000
#define maxm 500+100
#define eps 1e-10
#define ll long long
#define pa pair<int,int>
#define for0(i,n) for(int i=0;i<=(n);i++)
#define for1(i,n) for(int i=1;i<=(n);i++)
#define for2(i,x,y) for(int i=(x);i<=(y);i++)
#define for3(i,x,y) for(int i=(x);i>=(y);i--)
#define mod 100000000
using namespace std;
inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=*x+ch-'';ch=getchar();}
return x*f;
}
int n,m,tot,p[maxn];
bool v[maxn];
char s[maxn];
class bigg{
public:
int num[],len;
bigg()
{
memset(num,,sizeof(num));
len=;
}
inline bigg operator =(const bigg &b)
{
memset(num,,sizeof(num));
len=b.len;
for1(i,len)num[i]=b.num[i];
return(*this);
}
inline bigg operator =(int b)
{
memset(num,,sizeof(num));
len=;
while(b){num[++len]=b%mod;b/=mod;}
return(*this);
}
inline bigg operator *(int b)
{
ll x=;
for1(i,len)
{
x+=(ll)num[i]*b;
num[i]=x%mod;
x/=mod;
}
if(x)num[++len]=x;
return(*this);
}
inline bool operator <(const bigg&b)
{
if(len!=b.len)return len<b.len;
for3(i,len,)if(num[i]!=b.num[i])return num[i]<b.num[i];
return ;
}
inline void print()
{
printf("%d",num[len]);
for3(i,len-,)printf("%08d",num[i]);printf("\n");
}
};
bigg a[],b,c[];
int rk[];
bool cmp(int x,int y){return a[x]<a[y];}
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
for2(i,,maxn)
{
if(!v[i])p[++tot]=i;
for1(j,tot)
{
int k=p[j]*i;
if(k>maxn)break;
v[k]=;
if(i%p[j]==)break;
}
}
n=read();
for1(j,n)
{
memset(s,,sizeof(s));
scanf("%s",s);
m=strlen(s);
reverse(s,s+m);
for0(i,m-)s[i]-='';
a[j].len=(m+)/;
for0(i,a[j].len-)
a[j].num[i+]=s[i*]+*s[i*+]+*s[i*+]+*s[i*+]+*(s[i*+]+*s[i*+]+*s[i*+]+*s[i*+]);
rk[j]=j;
}
sort(rk+,rk+n+,cmp);
int j=;
b=;
for1(i,n)
{
c[rk[i]]=c[rk[i-]];
while(b<a[rk[i]])c[rk[i]]=b,b=b*p[j++];
}
for1(i,n)c[i].print();
return ;
}
哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈
用我的方法+压8位 怒排rank3
代码:
「Poetize3」Heaven Cow与God Bull的更多相关文章
- 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 ...
- 【Heaven Cow与God Bull】题解
题目 Description __int64 ago,there's a heaven cow called sjy... A god bull named wzc fell in love with ...
- LG5200 「USACO2019JAN」Sleepy Cow Sorting 树状数组
\(\mathrm{Sleepy Cow Sorting}\) 问题描述 LG5200 题解 树状数组. 设\(c[i]\)代表\([1,i]\)中归位数. 显然最终的目的是将整个序列排序为一个上升序 ...
- 「Poetize3」导弹防御塔
描述 Description Freda控制着N座可以发射导弹的防御塔.每座塔都有足够数量的导弹,但是每座塔每次只能发射一枚.在发射导弹时,导弹需要T1秒才能从防御塔中射出,而在发射导弹后,发射这枚导 ...
- 「Poetize3」绿豆蛙的归宿
描述 Description 给出一个有向无环图,起点为1终点为N,每条边都有一个长度,并且从起点出发能够到达所有的点,所有的点也都能够到达终点.绿豆蛙从起点出发,走向终点.到达每一个顶点时,如果有K ...
- joyoi1935 「Poetize3」导弹防御塔
#include <iostream> #include <cstring> #include <cstdio> #include <queue> #i ...
- 「POJ3613」Cow Relays
「POJ3613」Cow Relays 传送门 就一个思想:\(N\) 遍 \(\text{Floyd}\) 求出经过 \(N\) 个点的最短路 看一眼数据范围,想到离散化+矩阵快速幂 代码: #in ...
- 「笔记」折半搜索(Meet in the Middle)
思想 先搜索前一半的状态,再搜索后一半的状态,再记录两边状态相结合的答案. 暴力搜索的时间复杂度通常是 \(O(2^{n})\) 级别的.但折半搜索可以将时间复杂度降到 \(O(2 \times 2^ ...
- 「译」JUnit 5 系列:条件测试
原文地址:http://blog.codefx.org/libraries/junit-5-conditions/ 原文日期:08, May, 2016 译文首发:Linesh 的博客:「译」JUni ...
随机推荐
- 10.23 noip模拟试题
尼玛蛋pdf好难粘 直接写了 T1 /*开始写wa了 我真弱2333 关于p的排序规则不只是差值 为了字典序最小 还要拍别的*/ #include<cstdio> #include< ...
- C#--Session用完如何清除
Session.Abandon();//清除全部Session//清除某个SessionSession["UserName"] = null;Session.Remove(&quo ...
- 使用js使表单自动提交
function sub(){ document.yeepay.submit(); } setTimeout(sub,1000);//以毫秒为单位的.1000代表一秒钟.根据你需要修改这个时间. // ...
- JAAS - Document
JAAS 参考文档: JAAS Reference Guide JAAS Authentication Tutorial JAAS Authorization Tutorial LoginModule ...
- eclipse代码注释的设置
http://blog.csdn.net/shiyuezhong/article/details/8450578 1. eclipse用户名的设置: 在eclipse的安装路径下,打开eclipse. ...
- Android开发---支付宝功能接口(支付功能)(转载!)
最近在做一个关于购物商城的项目,项目里面付款这块我选的是调用支付宝的接口,因为用的人比较多. 在网上搜索了以下,有很多这方面的教程,但大部分教程过于陈旧,而且描述的过于简单.而且支付宝提供的接口一直在 ...
- jdbc - 连接数据库的url
MySql: driver:com.mysql.jdbc.Driver url: jdbc:mysql://localhost:3306/database_name SQL Server 2008: ...
- SQL 优化,全
性能不理想的系统中除了一部分是因为应用程序的负载确实超过了服务器的实际处理能力外,更多的是因为系统存在大量的SQL语句需要优化. 为了获得稳定的执行性能,SQL语句越简单越好.对复杂的SQL语句,要设 ...
- 344. Reverse String(C++)
344. Reverse String Write a function that takes a string as input and returns the string reversed. E ...
- 再看IOC, 读深入理解DIP、IoC、DI以及IoC容器
IoC则是一种 软件设计模式,它告诉你应该如何做,来解除相互依赖模块的耦合.控制反转(IoC),它为相互依赖的组件提供抽象,将依赖(低层模块)对象的获得交给第三方(系统)来控制,即依赖对象不在被依赖模 ...