[KMOI R1] 集合 First 题解
Fire_flame · · 题解
\mathbf{Solution}
\mathtt{15} 分做法
写一个 dfs 暴力,可以拿到
\mathtt{25} 分做法
不知道,期待比赛时有人拿到。
\mathtt{100} 分做法
我们考虑构造,令
将
所以
那么
故答案为
\mathtt{55} 分做法
因为模数是 long long。
没有用龟速乘或者提前取模
标程:
#include<bits/stdc++.h>//by Fire_flame
#define int long long
using namespace std;
const int MOD = 911451407;
int n;
int fpow(int a, int b){
int res = 1;
while(b){
if(b & 1)res = res * a % MOD;
a = a * a % MOD;
b >>= 1;
}
return res;
}
int ftime(int a, int b){
int res = 0;
while(b){
if(b & 1)res = (res + a) % MOD;
a = (a + a) % MOD;
b >>= 1;
}
return res;
}
signed main(){
scanf("%lld", &n);
printf("%lld", ftime(fpow(2, n - 1), n));
return 0;
}
标程二:
#include<bits/stdc++.h>//代码提供者:OI_LOSER_CGY
#define int long long
using namespace std;
int n,mod=911451407;
signed main(){
scanf("%lld",&n);
int res=n%mod,a=2;n--;
while(n){
if(n%2)res=res*a%mod;
a=a*a%mod,n/=2;
}
printf("%lld\n",res);
return 0;
}