結果

問題 No.1039 Project Euler でやれ
ユーザー 37zigen37zigen
提出日時 2020-02-27 21:27:35
言語 Java19
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,468 bytes
コンパイル時間 4,506 ms
コンパイル使用メモリ 74,356 KB
実行使用メモリ 56,256 KB
最終ジャッジ日時 2023-08-03 19:25:01
合計ジャッジ時間 8,673 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 143 ms
55,916 KB
testcase_04 AC 144 ms
55,336 KB
testcase_05 WA -
testcase_06 AC 127 ms
55,312 KB
testcase_07 AC 123 ms
55,516 KB
testcase_08 AC 127 ms
56,012 KB
testcase_09 AC 127 ms
55,700 KB
testcase_10 AC 123 ms
55,736 KB
testcase_11 AC 127 ms
56,088 KB
testcase_12 AC 127 ms
56,052 KB
testcase_13 AC 121 ms
56,020 KB
testcase_14 AC 127 ms
55,692 KB
testcase_15 WA -
testcase_16 AC 122 ms
56,084 KB
testcase_17 AC 121 ms
56,036 KB
testcase_18 AC 121 ms
55,916 KB
testcase_19 AC 120 ms
55,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;

class Main {
	public static void main(String[] args) throws Exception {
		new Main().run();
	}
	
	final long MOD=(long)1e9+7;
	
	long pow(long a,long n) {
		long ret=1;
		for(;n>0;n>>=1,a=a*a%MOD)if(n%2==1)ret=ret*a%MOD;
		return ret;
	}
	
	long inv(long a) {
		return pow(a,MOD-2);
	}
	
	long solve(long p,int e) {
		long[][] dp=new long[e+1][e+1];//dp[i][j]:=i個使用済み,p^jまで見た。
		dp[0][0]=1;
		for(int i=0;i<e;++i) {
			for(int j=0;j<=e;++j) {
				if(dp[i][j]==0)continue;
				for(int k=j+1;k<=e;++k) {
					for(int l=1;l<=e;++l) {
						if(i+k*l>e)continue;
						//(Z/p^k)^l
						long add=1;
						for(int m=0;m<l;++m) {
							add*=(pow(p,k*l)-pow(p,l*(k-1)+m))*pow(p,i)%MOD;
							add%=MOD;
						}
						dp[i+k*l][k]+=inv(add)*dp[i][j]%MOD;
						dp[i+k*l][k]%=MOD;
					}
				}
			}
		}
		long ret=0;
		for(int i=1;i<=e;++i)ret=(ret+dp[e][i])%MOD;
		ret=(ret%MOD+MOD)%MOD;
		return ret;
	}
	
	void run() {
		Scanner sc=new Scanner(System.in);
		int M=sc.nextInt();
		long fac=1;
		for(long i=1;i<=M;++i)fac=fac*i%MOD;
		long ans=1;
		for(long div=2;div<=M;++div) {
			int e=0;
			while(M%div==0) {
				M/=div;
				++e;
			}
			if(e>0) ans=ans*solve(div,e)%MOD;
		}
		ans=ans*fac%MOD;
		System.out.println(ans);
	}
	
	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
	
}
0