/*
* hdu2588/linux.c
* Created on: 2011-8-2
* Author : ben
*/
#include
<stdio.h>
#include
<math.h>

int phi(int x) {
int i, res = x, temp = (int) sqrt(x);
for (i = 2; i < temp + 1; i++) {
if (x % i == 0) {
res
= res / i * (i - 1);
while (x % i == 0) {
x
/= i;
}
}
}
if (x > 1) {
res
= res / x * (x - 1);
}
return res;
}

void work() {
int T, N, M, i, sqrtn, ans;
scanf(
"%d", &T);
while (T--) {
scanf(
"%d%d", &N, &M);
sqrtn
= sqrt(N);
ans
= 0;
for (i = 1; i < sqrtn; i++) {
if (N % i != 0) {
continue;
}
if (i >= M) {
ans
+= phi(N / i);
}
if (N / i >= M) {
ans
+= phi(i);
}
}
if (sqrtn * sqrtn == N && sqrtn >= M) {
ans
+= phi(sqrtn);
}
printf(
"%d\n", ans);
}
}

int main() {
#ifndef ONLINE_JUDGE
freopen(
"data.in", "r", stdin);
#endif
work();
return 0;
}

相关文章:

  • 2021-11-12
  • 2021-10-09
  • 2022-12-23
  • 2022-12-23
  • 2022-01-06
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-05-22
  • 2022-02-18
  • 2021-05-22
  • 2021-09-11
  • 2022-02-08
  • 2021-12-27
相关资源
相似解决方案