码迷,mamicode.com
首页 > 其他好文 > 详细

codeforces 1007B Pave the Parallelepiped

时间:2018-07-14 20:05:32      阅读:585      评论:0      收藏:0      [点我收藏+]

标签:pre   sync   pip   bool   tor   name   names   +=   []   

codeforces 1007B Pave the Parallelepiped

题意

题解

代码

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define sz(a) (int)a.size()
#define de(a) cout << #a << " = " << a << endl
#define dd(a) cout << #a << " = " << a << " "
#define all(a) a.begin(), a.end()
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
//---

const int N = 101010, M = 166;

int a[3], cnt[8], d[N];
map<pair<pii, int>, bool> vis;
ll f[M], f2[N];

void init() {
    rep(i, 1, M) {
        rep(j, 1, i+1) f[i] += 1ll * j * (i - j + 1);
        f2[i] = 1ll * i * (i+1) / 2;
    }
    rep(i, 1, N) {
        for(int j = 1; j * j <= i; ++j) if(i%j==0) {
            ++d[i];
            if(j != i/j) ++d[i];
        }
    }
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    init();
    int T;
    cin >> T;
    while(T--) {
        rep(i, 0, 3) cin >> a[i];
        cnt[1] = d[a[0]];
        cnt[2] = d[a[1]];
        cnt[4] = d[a[2]];
        cnt[3] = d[__gcd(a[0], a[1])];
        cnt[5] = d[__gcd(a[0], a[2])];
        cnt[6] = d[__gcd(a[1], a[2])];
        cnt[7] = d[__gcd(__gcd(a[0], a[1]), a[2])];
        cnt[3] -= cnt[7];
        cnt[5] -= cnt[7];
        cnt[6] -= cnt[7];
        cnt[1] -= cnt[3] + cnt[5] + cnt[7];
        cnt[2] -= cnt[3] + cnt[6] + cnt[7];
        cnt[4] -= cnt[5] + cnt[6] + cnt[7];
        ll ans = 0;
        vis.clear();
        rep(a, 1, 8) if(cnt[a] && (a&1)) rep(b, 1, 8) if(cnt[b] && (b>>1&1)) rep(c, 1, 8) if(cnt[c] && (c>>2&1)) {
            int x[] = {a, b, c};
            sort(x, x+3);
            int i = x[0], j = x[1], k = x[2];
            auto t = mp(mp(i, j), k);
            if(vis[t]) continue;
            vis[t] = 1;
            if(i == j && i == k) {
                ans += f[cnt[i]];
            } else if(i == j) {
                ans += f2[cnt[i]] * cnt[k];
            } else if(i == k) {
                ans += f2[cnt[i]] * cnt[j];
            } else if(j == k) {
                ans += f2[cnt[j]] * cnt[i];
            } else {
                ans += cnt[i] * cnt[j] * cnt[k];
            }
        }
        cout << ans << endl;
    }
    return 0;
}

codeforces 1007B Pave the Parallelepiped

标签:pre   sync   pip   bool   tor   name   names   +=   []   

原文地址:https://www.cnblogs.com/wuyuanyuan/p/9310727.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!