結果

問題 No.1039 Project Euler でやれ
ユーザー 37zigen37zigen
提出日時 2020-02-28 14:38:26
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,634 bytes
コンパイル時間 3,989 ms
コンパイル使用メモリ 74,176 KB
実行使用メモリ 57,736 KB
最終ジャッジ日時 2023-08-03 19:25:10
合計ジャッジ時間 5,908 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
55,432 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 144 ms
55,488 KB
testcase_04 AC 145 ms
55,668 KB
testcase_05 AC 129 ms
55,480 KB
testcase_06 AC 129 ms
55,868 KB
testcase_07 AC 126 ms
55,596 KB
testcase_08 AC 130 ms
56,020 KB
testcase_09 AC 129 ms
55,716 KB
testcase_10 AC 124 ms
56,080 KB
testcase_11 AC 129 ms
55,864 KB
testcase_12 AC 127 ms
53,848 KB
testcase_13 AC 122 ms
55,892 KB
testcase_14 AC 128 ms
55,584 KB
testcase_15 WA -
testcase_16 AC 121 ms
55,852 KB
testcase_17 AC 121 ms
55,808 KB
testcase_18 AC 123 ms
55,660 KB
testcase_19 AC 120 ms
55,572 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Scanner;

class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc=new Scanner(System.in);
		int M=sc.nextInt();
		new Main().run(M);
	}
	
	final long MOD=(long)1e9+7;
	
	long pow(long a,long n) {
		n%=MOD-1;
		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+2][e+1];//dp[i][j][k]:=p^i使用済み,p^jまで見た,k要素決定。
		dp[0][e+1][0]=1;
		for(int i=0;i<e;++i) {
			for(int j=e+1;j>=1;--j) {
				for(int n=0;n<e;++n) {
				if(dp[i][j][n]==0)continue;
					for(int k=j-1;k>=1;--k) {
						for(int l=1;l<=e;++l) {
							if(i+k*l>e||(k==1&&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))%MOD*pow(p,k*n*(l-1)+i)%MOD;
								add%=MOD;
							}
							//System.out.println("add="+add+" (Z/"+p+"^"+k+"Z)^"+l);
							dp[i+k*l][k][n+l]+=inv(add)*dp[i][j][n]%MOD;
							dp[i+k*l][k][n+l]%=MOD;
						}
					}
				}
			}
		}
		long ret=0;
		for(int i=1;i<=e;++i)for(int j=1;j<=e;++j)ret=(ret+dp[e][i][j])%MOD;
		ret=(ret%MOD+MOD)%MOD;
		return ret;
	}
	
	void run(int M_) {
		int M=M_;
		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