Guest User

Untitled

a guest
Jul 13th, 2018
746
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.76 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define forn(i, n) for (int i = 0; i < (int)(n); ++i)
  6.  
  7. inline int gcd(int a, int b) {
  8.     return a ? gcd(b % a, a) : b;
  9. }
  10.  
  11. int nd[100100];
  12. vector<int> p[6];
  13.  
  14. int f(int *a) {
  15.     int g[8];
  16.     g[1] = nd[a[0]];
  17.     g[2] = nd[a[1]];
  18.     g[4] = nd[a[2]];
  19.     g[3] = nd[gcd(a[0], a[1])];
  20.     g[5] = nd[gcd(a[0], a[2])];
  21.     g[6] = nd[gcd(a[1], a[2])];
  22.     g[7] = nd[gcd(a[0], gcd(a[1], a[2]))];
  23.     int ans1 = 0, ans2 = 0;
  24.     int x[3];
  25.     forn (mask, 1 << 6) {
  26.         if (mask == 0) {
  27.             continue;
  28.         }
  29.         x[0] = x[1] = x[2] = 0;
  30.         int cnt = 0;
  31.         forn (i, 6) {
  32.             if (mask & (1 << i)) {
  33.                 ++cnt;
  34.                 forn (j, 3) {
  35.                     x[j] |= 1 << p[i][j];
  36.                 }
  37.             }
  38.         }
  39.         if (cnt & 1) {
  40.             ans1 += g[x[0]] * g[x[1]] * g[x[2]];
  41.             ans2 += g[x[0] | x[1]] * g[x[2]];
  42.         } else {
  43.             ans1 -= g[x[0]] * g[x[1]] * g[x[2]];
  44.             ans2 -= g[x[0] | x[1]] * g[x[2]];
  45.         }
  46.     }
  47.     return (ans1 + ans2 * 3 + g[7] * 2) / 6;
  48. }
  49.  
  50. int main() {
  51.     int pcnt = 0;
  52.     forn (i, 3) {
  53.         forn (j, 3) {
  54.             if (i == j) {
  55.                 continue;
  56.             }
  57.             p[pcnt++] = {i, j, 3 - i - j};
  58.         }
  59.     }
  60.     for (int i = 1; i < 100100; ++i) {
  61.         for (int j = 1; j * j <= i; ++j) {
  62.             if (i % j) {
  63.                 continue;
  64.             }
  65.             ++nd[i];
  66.             if (j * j < i) {
  67.                 ++nd[i];
  68.             }
  69.         }
  70.     }
  71.     int T = 100000;
  72.     scanf("%d", &T);
  73.     forn (q, T) {
  74.         int a[3];
  75.         scanf("%d%d%d", &a[0], &a[1], &a[2]);
  76.         printf("%d\n", f(a));
  77.     }
  78.     return 0;
  79. }
Add Comment
Please, Sign In to add comment