Loading

Codeforces Round #818 (Div. 2) A Madoka and Strange Thoughts

Madoka and Strange Thoughts

唯一分解定理

\[gcd(a, b) = p_1^{min(ak_1, bk_1)} * p_2^{min(ak_2, bk_2)}... \]

\[lcm(a, b) = p_1^{max(ak_1, bk_1)} * p_2^{max(ak_2, bk_2)}... \]

根据上面两个式子就可以知道 \(\frac{lcm(a,b)}{gcd(a,b)}\) 其实就是质因数最大最小次幂相差多少

因为题目说 \(\frac{lcm(a,b)}{gcd(a,b)} \le 3\),因此 \(a\)\(b\) 之间就只能满足倍数为 \(1\)\(2\)\(3\)

下次见到要多想想上面两个式子

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <functional>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <deque>
#include <stack>
#include <ctime>
#include <cstdlib>
using namespace std;
typedef long long ll;
#define pii pair<int, int>
const ll maxn = 2e5 + 10;
const ll inf = 1e17 + 10;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    while(t--)
    {
        int n;
        cin >> n;
        int ans = n / 3 + n / 2;
        ans *= 2;
        ans += n;
        cout << ans << "\n";
    }
    return 0;
}
posted @ 2022-09-03 01:00  dgsvygd  阅读(297)  评论(0编辑  收藏  举报