其他分享
首页 > 其他分享> > Codeforces Round #818 (Div. 2) A Madoka and Strange Thoughts

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;
}

标签:Madoka,cin,int,ak,Codeforces,bk,818,ans,include
来源: https://www.cnblogs.com/dgsvygd/p/16651802.html