結果

問題 No.644 G L C C D M
ユーザー Pulmn
提出日時 2017-04-21 20:06:00
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 32 ms / 2,000 ms
コード長 533 bytes
コンパイル時間 487 ms
コンパイル使用メモリ 59,560 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-20 05:11:25
合計ジャッジ時間 2,175 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;

const int MAX_N=100005;
const ll mod=1e9+7;

vl Euler_Phi(){
	vl e(MAX_N);
	for(int i=2;i<MAX_N;i++){
		int n=i,res=n;
		for(int j=2;j*j<=n;j++) if(n%j==0){
			res=res/j*(j-1);
			while(n%j==0) n/=j;
		}
		if(n!=1) res=res/n*(n-1);
		e[i]=res;
	}
	return e;
}

int N,M;

int main(){
	cin>>N>>M;
	vl e=Euler_Phi();
	ll res=0;
	for(int i=2;i<=N/M;i++) (res+=2*e[i])%=mod;
	for(int i=1;i<N-1;i++) (res*=i)%=mod;
	cout<<res<<endl;
}
0