結果

問題 No.3038 フィボナッチ数列の周期
ユーザー testestesttestestest
提出日時 2018-01-26 07:15:57
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 190 ms / 3,000 ms
コード長 1,563 bytes
コンパイル時間 164 ms
コンパイル使用メモリ 30,456 KB
実行使用メモリ 45,904 KB
最終ジャッジ日時 2023-09-07 12:42:03
合計ジャッジ時間 5,952 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 175 ms
40,928 KB
testcase_01 AC 169 ms
40,924 KB
testcase_02 AC 173 ms
41,104 KB
testcase_03 AC 177 ms
41,040 KB
testcase_04 AC 175 ms
41,060 KB
testcase_05 AC 174 ms
41,076 KB
testcase_06 AC 172 ms
41,008 KB
testcase_07 AC 181 ms
41,236 KB
testcase_08 AC 171 ms
41,224 KB
testcase_09 AC 173 ms
41,108 KB
testcase_10 AC 172 ms
41,236 KB
testcase_11 AC 176 ms
41,096 KB
testcase_12 AC 177 ms
41,036 KB
testcase_13 AC 172 ms
41,116 KB
testcase_14 AC 174 ms
41,152 KB
testcase_15 AC 180 ms
41,180 KB
testcase_16 AC 190 ms
45,872 KB
testcase_17 AC 189 ms
45,872 KB
testcase_18 AC 180 ms
45,856 KB
testcase_19 AC 181 ms
45,808 KB
testcase_20 AC 181 ms
45,864 KB
testcase_21 AC 180 ms
45,800 KB
testcase_22 AC 187 ms
45,888 KB
testcase_23 AC 186 ms
45,832 KB
testcase_24 AC 187 ms
45,904 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#define M 1000000007
#define N 10000000

#define ll long long
#define rep(i,l,r)for(ll i=l;i<r;i++)
#define max(p,q)((p)>(q)?(p):(q))
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
int divisor[N+10];
void maked(int n){divisor[0]=-1;divisor[1]=1;ll i=2;for(;i*i<=n;i++)if(!divisor[i]){divisor[i]=i;for(ll j=i*i;j<=n;j+=i)if(!divisor[j])divisor[j]=i;}for(;i<=n;i++)if(!divisor[i])divisor[i]=i;}

void fib(int n,int m,ll*ans){
	ll temp[2],s[2]={0,1};
	ans[0]=1;ans[1]=0;
	while(n){
		if(n%2){
			temp[0]=s[0]*ans[0]+s[1]*ans[1];
			temp[1]=(s[0]+s[1])*(ans[0]+ans[1])-s[0]*ans[0];
			ans[0]=temp[0]%m;
			ans[1]=temp[1]%m;
		}
		temp[0]=s[0]*s[0]+s[1]*s[1];
		temp[1]=(s[0]+s[1])*(s[0]+s[1])-s[0]*s[0];
		s[0]=temp[0]%m;
		s[1]=temp[1]%m;
		n/=2;
	}
}

int f(int m){
	int ans,t;
	if(m%5==2||m%5==3)ans=t=2*m+2;
	else ans=t=m-1;

	while(t!=1){
		int d=t>N?2:divisor[t];
		ll b[2];
		fib(ans/d,m,b);
		if(b[0]==1&&b[1]==0){
			t/=d;
			ans/=d;
		}else{
			t/=d;
			while(divisor[t]==d)t/=d;
		}
	}
	return ans;
}

int pp[N+10];
int main(){
	maked(N);
	int n;
	scanf("%d",&n);
	while(n--){
		int p,k;
		scanf("%d%d",&p,&k);
		pp[p]=max(pp[p],k-1);

		if(p==2){
			pp[3]=max(pp[3],1);
		}
		else if(p==5){
			pp[2]=max(pp[2],2);
			pp[5]=max(pp[5],k);
		}else{
			int t=f(p)/2;
			int d=2,cnt=1;
			while(t!=1){
				while(divisor[t]==d){
					t/=divisor[t];
					cnt++;
				}
				pp[d]=max(pp[d],cnt);
				d=divisor[t],cnt=0;
			}
		}
	}
	int ans=1;
	rep(i,2,N)if(pp[i])ans=ans*pom(i,pp[i],M)%M;
	printf("%d\n",ans);
}
0