Goffi and GCD
思路
题目要求
显然有 对于 直接可以特判 ,对于 的时候也可以特判一定是 。
所以我们只要考虑 的情况:
最后再特判一下 的时候是一定有一个答案的。
代码
/*
Author : lifehappy
*/
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define endl '\n'
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const double pi = acos(-1.0);
const double eps = 1e-7;
const int inf = 0x3f3f3f3f;
ll eular(ll x) {
ll ans = x;
for(ll i = 2; i * i <= x; i++) {
if(x % i == 0) {
while(x % i == 0) {
x /= i;
}
ans = ans / i * (i - 1);
}
}
if(x != 1) ans = ans / x * (x - 1);
return ans;
}
const int mod = 1e9 + 7;
int main() {
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
// ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
ll n, k;
while (scanf("%lld %lld", &n, &k) != EOF) {
ll ans = 0;
if (k == 2 || n == 1) ans = 1;
else if (k == 1) {
for (ll i = 1; i * i <= n; i++) {
if (n % i == 0) {
if (i * i != n) ans = (ans + eular(n/i) * eular(i) * 2) % mod;
else ans = ans = (ans + eular(i) * eular(i)) % mod;
}
}
}
printf("%lld\n", ans);
}
return 0;
}