描述 Description
给定一个整数n,求一个整数m,满足m<=n,并且m/phi(m)的值最大。
注: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的更多相关文章

  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. 【Heaven Cow与God Bull】题解

    题目 Description __int64 ago,there's a heaven cow called sjy... A god bull named wzc fell in love with ...

  3. LG5200 「USACO2019JAN」Sleepy Cow Sorting 树状数组

    \(\mathrm{Sleepy Cow Sorting}\) 问题描述 LG5200 题解 树状数组. 设\(c[i]\)代表\([1,i]\)中归位数. 显然最终的目的是将整个序列排序为一个上升序 ...

  4. 「Poetize3」导弹防御塔

    描述 Description Freda控制着N座可以发射导弹的防御塔.每座塔都有足够数量的导弹,但是每座塔每次只能发射一枚.在发射导弹时,导弹需要T1秒才能从防御塔中射出,而在发射导弹后,发射这枚导 ...

  5. 「Poetize3」绿豆蛙的归宿

    描述 Description 给出一个有向无环图,起点为1终点为N,每条边都有一个长度,并且从起点出发能够到达所有的点,所有的点也都能够到达终点.绿豆蛙从起点出发,走向终点.到达每一个顶点时,如果有K ...

  6. joyoi1935 「Poetize3」导弹防御塔

    #include <iostream> #include <cstring> #include <cstdio> #include <queue> #i ...

  7. 「POJ3613」Cow Relays

    「POJ3613」Cow Relays 传送门 就一个思想:\(N\) 遍 \(\text{Floyd}\) 求出经过 \(N\) 个点的最短路 看一眼数据范围,想到离散化+矩阵快速幂 代码: #in ...

  8. 「笔记」折半搜索(Meet in the Middle)

    思想 先搜索前一半的状态,再搜索后一半的状态,再记录两边状态相结合的答案. 暴力搜索的时间复杂度通常是 \(O(2^{n})\) 级别的.但折半搜索可以将时间复杂度降到 \(O(2 \times 2^ ...

  9. 「译」JUnit 5 系列:条件测试

    原文地址:http://blog.codefx.org/libraries/junit-5-conditions/ 原文日期:08, May, 2016 译文首发:Linesh 的博客:「译」JUni ...

随机推荐

  1. jetty运行maven程序(修改及时生效,不需要重启jetty程序)

    jetty:run -Djetty:port=9999

  2. Datum Form Goole Android

    1. <TurboChargeYourUI-How to make your AndroidUI fast and efficient> 2. <The World of List ...

  3. Encapsulation.

    Access control is often referred to as implementation hiding. Wrapping data and methods within class ...

  4. dnsever 邮件记录

    记录,备忘

  5. Oracle AWR报告指标全解析-11011552

    1-5 Top 5 Timed EventsWaits : 该等待事件发生的次数, 对于DB CPU此项不可用Times : 该等待事件消耗的总计时间,单位为秒, 对于DB CPU 而言是前台进程所消 ...

  6. 【转】iOS开发之各种动画各种页面切面效果

    原文: http://www.cnblogs.com/ludashi/p/4160208.html?utm_source=tuicool 因工作原因,有段时间没发表博客了,今天就发表篇博客给大家带来一 ...

  7. JavaScript 字符串(String) 对象

    JavaScript 字符串(String) 对象 String 对象用于处理已有的字符块. JavaScript 字符串 一个字符串用于存储一系列字符就像 "John Doe". ...

  8. JavaScript_变量的自动转换和语句

    JS自动类型转换 var a = 1; var b = true; "==" 表示 可以自动类型转换,比较的是数值 "===" 表示可以自动类型转换,先比较数值 ...

  9. 查看Jquery版本

    1. $.fn.jquery > "1.11.1" 2. 通过这样可以 判断一个对象是否是jquery对象!!

  10. SGU 128.Snake

    时间限制:0.25s 空间限制:4m 题意: 在一个平面坐标中有N个点,现在要你用这N个点构造一个闭合图形,这个图形要满足以下条件: 1.这个图形要是闭合的:          2.图形上的点只能是给 ...