結果
問題 | No.1050 Zero (Maximum) |
ユーザー |
![]() |
提出日時 | 2020-05-08 22:37:49 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 11 ms / 2,000 ms |
コード長 | 1,511 bytes |
コンパイル時間 | 2,267 ms |
コンパイル使用メモリ | 195,820 KB |
最終ジャッジ日時 | 2025-01-10 09:03:54 |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 15 |
ソースコード
#include <bits/stdc++.h>using namespace std;typedef signed long long ll;#undef _P#define _P(...) (void)printf(__VA_ARGS__)#define FOR(x,to) for(x=0;x<(to);x++)#define FORR(x,arr) for(auto& x:arr)#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)#define ALL(a) (a.begin()),(a.end())#define ZERO(a) memset(a,0,sizeof(a))#define MINUS(a) memset(a,0xff,sizeof(a))//-------------------------------------------------------ll mo=1000000007;const int MAT=50;struct Mat { ll v[MAT][MAT]; Mat(){ZERO(v);};};Mat mulmat(Mat& a,Mat& b,int n=MAT) {ll mo2=4*mo*mo;int x,y,z; Mat r;FOR(x,n) FOR(y,n) r.v[x][y]=0;FOR(x,n) FOR(z,n) FOR(y,n) {r.v[x][y] += a.v[x][z]*b.v[z][y];if(r.v[x][y]>mo2) r.v[x][y] -= mo2;}FOR(x,n) FOR(y,n) r.v[x][y]%=mo;return r;}Mat powmat(ll p,Mat a,int n=MAT) {int i,x,y; Mat r;FOR(x,n) FOR(y,n) r.v[x][y]=0;FOR(i,n) r.v[i][i]=1;while(p) {if(p%2) r=mulmat(r,a,n);a=mulmat(a,a,n);p>>=1;}return r;}ll modpow(ll a, ll n = mo-2) {ll r=1;while(n) r=r*((n%2)?a:1)%mo,a=a*a%mo,n>>=1;return r;}int M,K;void solve() {int i,j,k,l,r,x,y; string s;cin>>M>>K;Mat A;FOR(i,M) {FOR(j,M) {A.v[(i+j)%M][i]++;A.v[(i*j)%M][i]++;}}Mat B=powmat(K,A,M);cout<<B.v[0][0]<<endl;}int main(int argc,char** argv){string s;int i;if(argc==1) ios::sync_with_stdio(false), cin.tie(0);FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);cout.tie(0); solve(); return 0;}