|
|
|
@ -2,7 +2,7 @@
|
|
|
|
|
using namespace std;
|
|
|
|
|
#define int long long
|
|
|
|
|
#define endl "\n"
|
|
|
|
|
const int maxn = 10000;
|
|
|
|
|
|
|
|
|
|
const int Six = 166666668; // 6,2关于mod的乘法逆元
|
|
|
|
|
const int Two = 500000004;
|
|
|
|
|
const int mod = 1e9 + 7; // 尽量这样定义mod ,减少非必要的麻烦
|
|
|
|
@ -28,6 +28,7 @@ signed main() {
|
|
|
|
|
while (cin >> n >> m) {
|
|
|
|
|
int sum = F(1, n), ans = 0; // 计算总和sum
|
|
|
|
|
|
|
|
|
|
// 质因子分解
|
|
|
|
|
int t = m; // 复制出来
|
|
|
|
|
for (int i = 2; i * i <= t; i++) {
|
|
|
|
|
if (t % i == 0) {
|
|
|
|
@ -37,24 +38,24 @@ signed main() {
|
|
|
|
|
}
|
|
|
|
|
if (t > 1) p.push_back(t);
|
|
|
|
|
|
|
|
|
|
int item = 1 << p.size(); /// 开始容斥
|
|
|
|
|
|
|
|
|
|
// 开始容斥
|
|
|
|
|
// 例如有3个因子,那么item=1<<3=8(1000二进制)
|
|
|
|
|
// 然后i从1开始枚举直到7(111二进制),i中二进制的位置1表式取这个位置的因子
|
|
|
|
|
// 例如i=3(11二进制) 表示去前两个因子,i=5(101)表示取第1个和第3个的因子
|
|
|
|
|
for (int i = 1; i < item; i++) {
|
|
|
|
|
int num = 0, x = 1;
|
|
|
|
|
|
|
|
|
|
for (int j = 0; j < p.size(); j++) {
|
|
|
|
|
if (1 & (i >> j)) num++, x *= p[j];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (num & 1)
|
|
|
|
|
ans = (ans + F(x, n / x)) % mod; // 根据容斥,取奇数个因子时,应加上
|
|
|
|
|
for (int i = 1; i < (1 << p.size()); i++) {
|
|
|
|
|
int cnt = 0, s = 1;
|
|
|
|
|
for (int j = 0; j < p.size(); j++)
|
|
|
|
|
if ((i >> j) & 1) {
|
|
|
|
|
cnt++;
|
|
|
|
|
s *= p[j];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (cnt & 1)
|
|
|
|
|
ans = (ans + F(s, n / s)) % mod; // 根据容斥,取奇数个因子时,应加上
|
|
|
|
|
else
|
|
|
|
|
ans = ((ans - F(x, n / x)) % mod + mod) % mod;
|
|
|
|
|
ans = ((ans - F(s, n / s)) % mod + mod) % mod; // 偶数的减,减法需要防负数
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
printf("%lld\n", ((sum - ans) % mod + mod) % mod);
|
|
|
|
|
// 补集,标准取模动作
|
|
|
|
|
cout << ((sum - ans) % mod + mod) % mod << endl;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|