結果

問題 No.1728 [Cherry 3rd Tune] Bullet
ユーザー kotatsugame
提出日時 2021-11-06 04:29:32
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 55 ms / 2,000 ms
コード長 614 bytes
コンパイル時間 797 ms
コンパイル使用メモリ 79,136 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-06 22:30:01
合計ジャッジ時間 1,998 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 27
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:10:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   10 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<atcoder/modint>
using namespace std;
using mint=atcoder::modint1000000007;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int T,N,C;
int cnt[10000];
main()
{
	cin>>T;
	for(;T--;)
	{
		cin>>N>>C;
		vector<int>d;
		for(int p=1;p*p<=N;p++)if(N%p==0)
		{
			d.push_back(p);
			if(p<N/p)d.push_back(N/p);
		}
		sort(d.begin(),d.end());
		mint ans=mint(C).pow(N)*N;
		for(int i=d.size();i--;)
		{
			cnt[i]=N/d[i];
			for(int j=i+1;j<d.size();j++)if(d[j]%d[i]==0)cnt[i]-=cnt[j];
			ans+=mint(C).pow(2*d[i])*cnt[i];
		}
		cout<<(ans/(2*N)).val()<<endl;
	}
}
0