結果
| 問題 |
No.1659 Product of Divisors
|
| コンテスト | |
| ユーザー |
milanis48663220
|
| 提出日時 | 2021-08-27 22:08:55 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 4,180 bytes |
| コンパイル時間 | 1,250 ms |
| コンパイル使用メモリ | 118,772 KB |
| 最終ジャッジ日時 | 2025-01-24 03:10:40 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 WA * 1 |
| other | AC * 2 WA * 21 |
ソースコード
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>
#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
class ModInt{
public:
ll v;
ModInt(ll _v = 0){
if(_v < 0) _v = (_v%MOD)+MOD;
if(_v >= MOD) _v %= MOD;
v = _v;
}
ModInt operator+(ll n){
return ModInt((v+n)%MOD);
}
ModInt operator-(ll n){
return ModInt((v-n+MOD)%MOD);
}
ModInt operator*(ll n){
if(n >= MOD) n %= MOD;
return ModInt((v*n)%MOD);
}
ModInt operator/(ll n){
return ModInt((ModInt(n).inv()*v).v%MOD);
}
void operator+=(ll n){
v = (v+n)%MOD;
}
void operator-=(ll n){
v = (v-n+MOD)%MOD;
}
void operator*=(ll n){
v = (v*n+MOD)%MOD;
}
ModInt operator+(ModInt n){
return ModInt((v+n.v)%MOD);
}
ModInt operator-(ModInt n){
return ModInt((v-n.v+MOD)%MOD);
}
ModInt operator*(ModInt n){
return ModInt((v*n.v)%MOD);
}
ModInt operator/(ModInt n){
return ModInt((n.inv()*v).v%MOD);
}
void operator+=(ModInt n){
v = (v+n.v)%MOD;
}
void operator-=(ModInt n){
v = (v-n.v+MOD)%MOD;
}
void operator*=(ModInt n){
v = (v*n.v)%MOD;
}
void operator=(ModInt n){
v = n.v;
}
bool operator==(ModInt n){
return v == n.v;
}
bool operator!=(ModInt n){
return v != n.v;
}
void operator=(ll n){
v = n%MOD;
}
ModInt inv(){
if(v == 1) return ModInt(1);
else return ModInt(MOD-ModInt(MOD%v).inv().v*(MOD/v)%MOD);
}
};
ostream& operator<<(ostream& os, const ModInt& m){
os << m.v;
return os;
}
istream & operator >> (istream &in, ModInt &m){
in >> m.v;
return in;
}
ModInt pow(ModInt a, ll n) {
assert(n >= 0);
ModInt ans = 1;
ModInt tmp = a;
for (int i = 0; i <= 60; i++) {
ll m = (ll)1 << i;
if (m & n) {
ans *= tmp;
}
tmp *= tmp;
}
return ans;
}
using mint = ModInt;
#define N_MAX 200002
ModInt inv[N_MAX],fac[N_MAX],finv[N_MAX];
void init(){
fac[0]=1;fac[1]=1;
finv[0]=1;finv[1]=1;
inv[1]=1;
for(int i=2;i<N_MAX;i++){
inv[i]=ModInt(MOD)-inv[MOD%i]*(MOD/i);
fac[i]=fac[i-1]*(ll) i;
finv[i]=finv[i-1]*inv[i];
}
}
mint comb(ll n, ll r){
if(n-r < r) r = n-r;
mint ans = 1;
for(ll i = 1; i <= r; i++){
ans *= inv[i];
ans *= n-i+1;
}
return ans;
}
using P = pair<ll, int>;
vector<P> factorize(ll n){
ll m = n;
vector<P> ans;
for(ll p = 2; p*p <= n; p++){
if(m%p == 0){
int cnt = 0;
while(m%p == 0){
m /= p;
cnt++;
}
ans.push_back(P(p, cnt));
}
}
if(m != 1) ans.push_back(P(m, 1));
return ans;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout << setprecision(10) << fixed;
init();
ll n, k; cin >> n >> k;
auto v = factorize(n);
int m = v.size();
vector<mint> all(m), ng(m);
for(int i = 0; i < m; i++){
auto [c, x] = v[i];
all[i] = pow(mint(x+1), k);
ng[i] = comb(k+x-1, x-1);
// debug(ng[i])
// cout << c << "^" << x << ' ';
}
// cout << endl;
mint ans = 0;
for(int i = 0; i < (1<<m); i++){
mint tmp = 1;
for(int j = 0; j < m; j++){
if(i&(1<<j)) {
tmp *= MOD-1;
tmp *= ng[j];
}else{
tmp *= all[j];
}
}
ans += tmp;
}
cout << ans << endl;
}
milanis48663220