結果

問題 No.1039 Project Euler でやれ
ユーザー testestesttestestest
提出日時 2020-02-18 10:55:44
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 951 bytes
コンパイル時間 1,204 ms
コンパイル使用メモリ 30,788 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-07 21:32:46
合計ジャッジ時間 2,297 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 4 ms
4,380 KB
testcase_02 AC 4 ms
4,380 KB
testcase_03 AC 6 ms
4,380 KB
testcase_04 AC 6 ms
4,380 KB
testcase_05 AC 5 ms
4,380 KB
testcase_06 AC 4 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 4 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 4 ms
4,376 KB
testcase_16 AC 0 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 0 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
#define M 1000000007

int powmod(long long a,int n,int m){
	long long x=1;
	a%=m;
	while(n){
		if(n%2)x=x*a%m;
		a=a*a%m;
		n/=2;
	}
	return x;
}

int ee[100]={100};//番兵

int dfs(int p,int rest,int cnt){
	if(rest==0){
		long long ans=1;
		ee[cnt+1]=0;//番兵
		int idx=0;
		for(int i=1;i<=cnt;i++){
			int c=i,d=i;
			while(ee[c+1]==ee[i])c++;
			while(ee[d-1]==ee[i])d--;
			ans=ans*(powmod(p,cnt+1-d,M)-powmod(p,cnt-i,M))%M;
			idx+=ee[i]*(d-1)+(ee[i]-1)*c;
		}
		ans=ans*powmod(p,idx,M)%M;
		return powmod(ans,M-2,M);
	}
	
	long long ans=0;
	for(int i=1;i<=ee[cnt]&&i<=rest;i++){
		ee[cnt+1]=i;
		ans+=dfs(p,rest-i,cnt+1);
	}
	return ans%M;
}

int f(int n){
	long long ans=1;
	for(int i=1;i<=n;i++)ans=ans*i%M;
	
	for(int p=2;p*p<=n;p++)if(n%p==0){
		int e=0;
		while(n%p==0)n/=p,e++;
		ans=ans*dfs(p,e,0)%M;
	}
	if(n!=1)ans=ans*dfs(n,1,0)%M;
	return (ans+M)%M;
}

int main(){
	int n;
	scanf("%d",&n);
	printf("%d\n",f(n));
}
0