涂颜色(欧拉定理 + 大数模拟取模)

it2026-01-24  4

题目地址 每一行只有两种情况,与列无关,所以答案时 2 n 2^n 2n

因为n很大很大,所以 由欧拉定理 当a与mod互质时 a b a^b ab(模 mod) = a b 模 p h i ( m o d ) a^{b 模 phi(mod)} abphi(mod) (模 mod)= a b ( 模 m o d − 1 ) a^{b(模 mod-1)} ab(mod1)(模 mod) , 数组模拟取模,把 n 给缩小。

最后快速幂就行了。

#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); #include<bits/stdc++.h> #define int long long using namespace std; typedef pair<int,int> pii; typedef long long ll; const int INF = 0x3f3f3f3f; const double eps = 1e-5; const int mod = 1000000007; const int N = 1e6+10; int qmi(int a,int b){ int res = 1; while(b){ if(b & 1) res = res*a%mod; a = a*a%mod; b >>= 1; } return res; } //这里可以看成a*b = a%mod * b%mod % mod int modd(string s){ int d = 0; for(int i=0;i<(int)s.size();i++) d = (d*10+s[i]-'0') % (mod-1); return d; } signed main(){ IOS; #ifdef ddgo freopen("C:\\Users\\asus\\Desktop\\ddgoin.txt","r",stdin); #endif string n,m; while(cin>>n>>m){ int nn = modd(n); cout<<qmi(2,nn)<<endl; } return 0; }
最新回复(0)