結果

問題 No.644 G L C C D M
ユーザー Lepton_sLepton_s
提出日時 2018-02-02 22:40:47
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 272 ms / 2,000 ms
コード長 3,056 bytes
コンパイル時間 1,189 ms
コンパイル使用メモリ 116,720 KB
実行使用メモリ 5,792 KB
最終ジャッジ日時 2023-08-30 02:20:22
合計ジャッジ時間 2,812 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,384 KB
testcase_11 AC 2 ms
4,384 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 12 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 3 ms
4,380 KB
testcase_19 AC 2 ms
4,384 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,384 KB
testcase_22 AC 272 ms
5,792 KB
testcase_23 AC 102 ms
4,888 KB
testcase_24 AC 59 ms
4,740 KB
testcase_25 AC 3 ms
4,380 KB
testcase_26 AC 2 ms
4,388 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<P,ll> PPI;
typedef pair<ll,P> PIP;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vp;
#define PQ(T) priority_queue<T,vector<T>,greater<T>>
#define PQ2(T) priority_queue<T>
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define REP(i,a,b) for(ll (i)=a;(i)<(ll)(b);++(i))
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n+1)
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) ((x)=min((x),(y)))
#define chmax(x,y) ((x)=max((x),(y)))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
#define DEBUG(x) cerr<<"line ("<<__LINE__<<")  "<<#x<<": "<<x<<endl;
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}
#define N 110000
ll fact[N], d[N], e[N], p[N];

bool isPrime(ll x){
	if(x<=1) return false;
	for(ll i = 2; i*i<=x; i++) if(x%i==0) return false;
	return true;
}

ll rec(ll x, ll n, ll t){
	//if(x==6) cerr<<x<<" "<<" "<<t<<endl;
	if(d[x]) return d[x];
	if(x==1) return 0;
	ll x2 = x;
	d[x] = n/x*t;
	for(ll i = 2; i*i <= x2; i++){
		if(x2%i) continue;
		x2 /= i;
		d[x] += rec(x/i, n, -t);
	}
	if(x2) d[x] += rec(x/x2, n, -t);
	return d[x];
}

ll solve(ll x, ll n){
	ll y = 1, t = -1;
	for(ll i = 2; i*i <= x; i++){
		if(!(x%i)){
			y *= i;
			t *= -1;
			while(!(x%i)) x /= i;
		}
	}
	if(x>1){
		y *= x;
		t *= -1;
	}
	ll res = 0;
	if(y==1) return 1;
	for(ll i = 1; i*i <= y; i++){
		if(y%i) continue;
		if(i>1) res += n/i*e[i];
		if(i*i!=y) res += n/(y/i)*e[y/i];
	}
	return res;
}
int main(){
	ll n, m;
	cin>>n>>m;
	fact[0] = 1;
	rep(i, n) fact[i+1] = fact[i]*(i+1)%mod;
	ll res = 0;
	/*for(ll i = m; i <= n; i+=m){
		ll n2 = n/m, i2 = i/m;
		//cerr<<n2<<" "<<i2<<" "<<(n2-n2/i2)<<endl;
		ll t = n2-n2/i2;
		if(i2==1) t = n2-1;
		(res+=t*fact[n-2])%=mod;
	}*/
	ll n2 = n/m;
	for(ll i = 2; i <= n2; i++){
		if(p[i]) continue;
		e[i] = 1;
		for(ll j = i*2; j <= n2; j+=i){
			if(e[j/i]) e[j] = -e[j/i];
			p[j] = 1;
		}
	}
	ll cnt = 0;
	for(ll i = 1; i <= n2; i++){
		ll t = solve(i, n2);
		cnt += t;
		//cerr<<i<<" "<<t<<endl;
		//cnt += solve(i, n2);
		//cerr<<cnt<<endl;
		//if(isPrime(i)) cnt += n2/i;
	}
	res = max(0LL, (n2*n2-cnt))%mod*fact[n-2]%mod;
	cout<<res<<endl;
	//rep(i, 20) cerr<<i<<": "<<e[i]<<endl;
	return 0;
}
0