CodeChef November Challenge 2013 部分题解

时间:2023-03-09 16:41:29
CodeChef  November Challenge 2013 部分题解

http://www.codechef.com/NOV13 还在比...我先放一部分题解吧...

Uncle Johny 排序一遍

struct node{
int val;
int pos;
}a[MAXN];
int cmp(node a,node b){
return a.val < b.val;
}
int main(){
int T,n,m;
while(cin>>T){
while(T--){
cin>>n;
for(int i = ; i < n ; i++){
cin>>a[i].val;
a[i].pos = i+;
}
cin>>m;
sort(a,a+n,cmp);
for(int i = ; i < n ; i++){
if(a[i].pos == m){
cout<<i+<<endl;
break;
}
}
}
}
return ;
}

Missing some chairs 简单快速幂

LL pow_mod(LL a, LL b){
if(b == ) return a;
LL x = pow_mod(a,b/),ret;
if(b&){
ret = ((x * x)%MOD * a) % MOD;
}else ret = (x * x) % MOD;
return ret;
}
int main(){
int T;
cin>>T;
while(T--){
LL n;
cin>>n;
LL c = pow_mod(,n);
cout<<c-<<endl;
}
return ;
}

Yet Another Cute Girl

因子个数为素数的可能只有可能是pi^(pj-1)次幂..其中p是素数

对于pj=2,区间素数筛,筛到sqrt(N)就行了...有O(n)的做法但我懒得写...其他的情况直接处理[L,R]内pi^(pj-1)的个数,加起来即可...

考虑到pow可能爆LL,这个很坑..我应该是卡过的...

LL cnt;
bool prime[MAXN];
LL pri[MAXN];
bool p[MAXN];
LL L,R;
void pre_prime(){
cnt = ;
prime[] = prime[] = ;
for(int i = ; i < MAXN ; i++){
if(!prime[i]) pri[cnt++] = i;
for(int j = ; j < cnt && i * pri[j] <= MAXN ; j++){
prime[i * pri[j]] = ;
if(i % pri[j] == ) break;
}
}
}
LL mpow(LL a, LL b){
LL ret = ;
for(LL i = ; i < b ; i++){
LL tmp = ret * a;
if(tmp > LINF || tmp < ret) return -;
ret = tmp;
}
return ret;
}
LL solve(){
LL ct = ;
mem(p,);
for(LL i = ; i < cnt ; i++){
for(LL j = ; j < cnt ; j++){
LL q = mpow(pri[j],pri[i]-);
if(q == -) break;
if(q >= L && q <= R){
ct++;
}
}
}
for(LL j = ; j < cnt ; j++){
LL i;
L % pri[j] == ? i = L : i = (L/pri[j]+)*pri[j];
if(i < MAXN && prime[i] == ) i = i*;
for(i ; i <= R ; i+=pri[j]) p[i-L] = true;
}
for(LL i = L ; i <= R ; i++){
if(p[i-L] == false && i != ){
ct++;
}
}
return ct;
}
int main(){
pre_prime();
int T;
cin>>T;
while(T--){
cin>>L>>R;
LL res = solve();
cout<<res<<endl;
}
return ;
}

Square Digit Squares 预处理一遍完全平方数,就没多少个

LL a[MAXN];
int cnt = ;
bool judge(LL x){
while(x){
LL y = x%;
if(y != && y != && y != && y != ) return false;
x/=;
}
return true;
}
void pre(){
for(LL i = ; i*i <= (LL)pow((LL),(LL))+ ; i++){
if(judge(i*i)){
a[cnt++] = i*i;
}
}
}
int main(){
pre();
int T;
cin>>T;
while(T--){
LL ax,bx;
cin>>ax>>bx;
int ct = ;
for(int i = ; i < cnt ; i++)
if(a[i] >= ax && a[i] <= bx) ct++;
cout<<ct<<endl;
}
return ;
}

Superpowers of 2 还是幂取模,一套题出两次我就不吐槽了,也许LL会WA

ULL change(ULL a){
ULL ret = ;
int p[],cnt = ;
while(a){
p[cnt++] = a%;
a/=;
}
for(int i = cnt- ; i >= ; i--){
ret = ret * + p[i];
}
return ret;
}
ULL pow_mod(ULL a, ULL b){
if(b == ) return a;
ULL x = pow_mod(a,b/),ret;
if(b&) ret = ((x * x)%MOD * a) % MOD;
else ret = (x * x) % MOD;
return ret;
}
int main(){
int T;
cin>>T;
while(T--){
int n;
cin>>n;
ULL x = pow_mod(,change(n));
cout<<(x*x)%MOD<<endl;
}
return ;
}