結果

問題 No.1164 GCD Products hard
ユーザー fura
提出日時 2020-08-14 03:23:33
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 273 ms / 2,500 ms
コード長 926 bytes
コンパイル時間 2,898 ms
コンパイル使用メモリ 197,048 KB
最終ジャッジ日時 2025-01-12 22:20:42
ジャッジサーバーID
(参考情報)
judge4 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 27
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:36:25: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   36 |         int a,b,n; scanf("%d%d%d",&a,&b,&n);
      |                    ~~~~~^~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using lint=long long;

class Eratosthenes_sieve{
	vector<bool> er;
	vector<int> p;
public:
	Eratosthenes_sieve(int n):er(n+1,true){
		if(n>=0) er[0]=false;
		if(n>=1) er[1]=false;
		for(int i=2;i*i<=n;i++) if(er[i]) for(int j=i*i;j<=n;j+=i) er[j]=false;
		rep(i,n+1) if(er[i]) p.emplace_back(i);
	}

	vector<int> primes()const{ return p; }

	bool is_prime(int a)const{
		assert(a<=(int)er.size()-1);
		return a>=0 && er[a];
	}
};

const int MOD=1e9+7;

lint modpow(lint a,lint k,int m){
	lint r=1;
	for(lint x=a%m;k>0;k>>=1,x=x*x%m) if(k&1) r=r*x%m;
	return r;
}

int main(){
	int a,b,n; scanf("%d%d%d",&a,&b,&n);

	Eratosthenes_sieve E(b);

	int ans=1;
	for(auto p:E.primes()){
		lint k=0;
		for(lint q=p;q<=b;q*=p){
			k+=modpow(b/q-(a-1)/q,n,MOD-1);
		}
		k%=MOD-1;
		ans=ans*modpow(p,k,MOD)%MOD;
	}
	printf("%d\n",ans);

	return 0;
}
0