結果

問題 No.1039 Project Euler でやれ
ユーザー kotatsugamekotatsugame
提出日時 2020-04-24 22:32:51
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 1,235 bytes
コンパイル時間 718 ms
コンパイル使用メモリ 75,980 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-07 21:33:58
合計ジャッジ時間 1,625 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,380 KB
testcase_01 AC 5 ms
4,376 KB
testcase_02 AC 5 ms
4,376 KB
testcase_03 AC 7 ms
4,380 KB
testcase_04 AC 7 ms
4,376 KB
testcase_05 AC 6 ms
4,380 KB
testcase_06 AC 5 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 4 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 5 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 4 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:49:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
   49 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<vector>
using namespace std;
const long mod=1e9+7;
long power(long a,long b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}
long dfs(long p,int e,int nxt,vector<int>n,vector<int>k)
{
	if(e==0)
	{
		long ret=1;
		for(int i=0;i<n.size();i++)
		{
			ret=ret*power(p,(n[i]-1)*k[i]*k[i])%mod;
			long pk=power(p,k[i]),pj=1;
			for(int j=0;j<k[i];j++)
			{
				ret=ret*(pk+mod-pj)%mod;
				pj=pj*p%mod;
			}
			for(int j=0;j<n.size();j++)if(i!=j)
			{
				ret=ret*power(pk,n[j<i?j:i]*k[j])%mod;
			}
		}
		return power(ret,mod-2);
	}
	else if(e-nxt>=0)
	{
		long ret=0;
		for(int nk=0;e>=nxt*nk;nk++)
		{
			if(nk!=0)
			{
				n.push_back(nxt);
				k.push_back(nk);
			}
			(ret+=dfs(p,e-nxt*nk,nxt+1,n,k))%=mod;
			if(nk!=0)
			{
				n.pop_back();
				k.pop_back();
			}
		}
		return ret;
	}
	else return 0L;
}
int M;
main()
{
	cin>>M;
	long ans=1;
	for(int i=1;i<=M;i++)ans=ans*i%mod;
	vector<pair<int,int> >pf;
	for(int i=2;i*i<=M;i++)
	{
		if(M%i==0)
		{
			int c=0;
			while(M%i==0)M/=i,c++;
			pf.push_back(make_pair(i,c));
		}
	}
	if(M>1)pf.push_back(make_pair(M,1));
	for(pair<int,int>pff:pf)
	{
		long p=pff.first,e=pff.second;
		ans=ans*dfs(p,e,1,vector<int>(),vector<int>())%mod;
	}
	cout<<ans<<endl;
}
0