「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 ...
随机推荐
- Qapp使用总结
QApp构建项目总结 1.view module 区别
- mysql 安装配置详解
作为演示,是不可能完全模拟到生产环境的,因此不可能尽善尽美.由于是在virtualbox里面的centos6.5最小化安装版中安装配置mysql,因此前期的准备工作有很多,那么开始吧.添加一块硬盘,用 ...
- 前端自动化构建工具 Gulp 使用
一个月没写博客了,今天有时间,就写个gulp的入门使用吧.. 简介:gulp是一个前端自动化构建工具,可以实现代码的检查.压缩.合并……等等,gulp是基于Node.js的自动任务运行器 一.安装No ...
- 用WebStorm调试本地html(含嵌入的javascript).
题外话: 以前很少能调试,甚至以为不能调试(好笨),后来我看了一本叫做<<Learning Three.js>>的一本书后,里面推荐有几种javascript的编辑工具,都蛮好 ...
- 在iframe中获取iframe外的对象
parent.document.getElementById("dom ID"); $($(parent.document.getElementById("video-i ...
- php数组(array)输出三种形式
$bbbb=array("11"=>"aaa","22"=>"bbb"); //只能输出值value不能输出 ...
- gdb小结
testGdb.c #include<stdio.h> int getSum(int a,int b){ printf("a+b=%d\n",a+b); return ...
- yii2源码学习笔记(四)
继续了解组件Component.php /** * Returns a value indicating whether a property is defined for this componen ...
- php 购物车完整实现代码
1.商品展示页面 代码如下: <table width="255" border="0" cellspacing="0" cellpa ...
- 入门5:PHP 语法基础——流程控制
一.if...else 语句 if( ) else{ } 如果 .... 就.... 否则.... if(判断){ 判断成立 则执行该表达式 }else{ 如果上方判断都不成立 则执行该表达式 } i ...