简单的玄学(random)
题目描述:
样例输入:
样例1: 3 2 样例2: 1 3 样例3: 4 3
样例输出:
样例1: 1 8 样例2: 1 1 样例3: 23 128
提示:
时间限制:1000ms
空间限制:512MByte
直接上题解看看吧,不过这个题解跟没说一样。。。已经知道的他都说了,不知道的他只字未提QAQ。///。。
#pragma GCC optimize(2) #include<bits/stdc++.h> #define ll long long #define mod 1000003 using namespace std; ll n,m,fz,fm,ny,cm; inline ll ksm(ll t,ll ci) { ll ans = 1; ll tem = t; while(ci) { if(ci & 1) { ans *= tem; ans %= mod; } tem *= tem; tem %= mod; ci >>= 1; } return ans; } int main(){ scanf("%lld%lld",&n,&m); ny = ksm(2 , mod-2); cm = ksm(2 , n); if(m > mod) { ll num=n,ans; for (ll i=2; i<=(m-1); i <<= 1) num += (m - 1) / i; ans = ksm(ksm(2 , n) , m) * ksm(ny , num) % mod; printf("%lld %lld",ans,ans); return 0; } if(n <= log2(m)) { printf("1 1"); return 0; } fz = 1; ll cnt = 0; for(ll i=1;i<=m-1;++i) { ll temp = i; ll ce = (cm - i) % mod; while(!(temp & 1)) { cnt++; temp >>= 1; ce = ce * ny % mod; } fz = fz * ce % mod; } fm = ksm(cm , m - 1) % mod * ksm(ny , cnt) % mod; fz = (fm - fz + mod) % mod; printf("%lld %lld",fz,fm); }