43552023-03-26 18:36:39hackemonFőzet készítéscpp17Accepted 50/50340ms6844 KiB
#include <bits/stdc++.h>
using namespace std;
//using namespace std::chrono;

#define pii pair<int,int>
#define pb push_back
#define vi vector<int>
#define vb vector<bool>
#define vl vector<ll>
#define vvi vector<vi>
#define vvb vector<vb>
#define vvl vector<vl>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define fScan {ios_base::sync_with_stdio(false); cin.tie(NULL);}
#define rep(i, a, b) for(int i = a; i < (b); i++)
#define REP(i, n) for(int i = 0;i <(n); i++)
using ll = long long;
using ld = long double;
ll mod = 1000000007;

const char ny =  '\n';

bool prime(ll a) {
    if (a==1) return 0;
    for (int i=2;i*i<=a;++i)
    {
        if (a%i==0) return 0;
    }
    return 1;
}

ll gcd(ll a,ll b) {
    if (b==0) return a;
    return gcd(b,a%b);
}

ll lcm(ll a,ll b)
{
    return a/gcd(a,b)*b;
}

ll min(int a, ll b) {
    if(a< b) return a;
    else return b;
}





    vector<vector<int>> dp(501, vector<int>(501, 0));
    

    void precal() {
        vector<pair<int,int>> p;
        for(int i = 1;i <= 32;i++ ) {
            for(int z = 1;z <= 32;z++ ) {
                if(__gcd(i, z) == 1) {
                    p.push_back({i, z});
                }
            }
        }
        
        for(int i = 0;i < p.size();i++ ) {
            for(int z = 500;z >= p[i].first;z--) {
                for(int h = 500;h >= p[i].second;h--) {
                        dp[z][h] = max(dp[z][h], dp[z - p[i].first][h - p[i].second] + 1);
                }
            }
        }
    }


    void solve() { 
        int n, m;
        cin >> n >> m;
        cout << dp[n][m] << endl;
    }


int main()
{
    fScan


    precal();


    int t = 1;
    //comment out if necessary
    cin>> t;


    //auto start = high_resolution_clock::now();
    while(t-- ) {
        solve();
    }
    //auto end = high_resolution_clock::now();
    //auto dur = duration_cast<milliseconds>(end-start);
    //cout<< "runtime: " << dur.count() << " milliseconds" << '\n';
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/0335ms3868 KiB
2Accepted0/0338ms4108 KiB
3Accepted3/3335ms4188 KiB
4Accepted2/2335ms4320 KiB
5Accepted3/3335ms4524 KiB
6Accepted2/2335ms4608 KiB
7Accepted3/3337ms4680 KiB
8Accepted2/2337ms4672 KiB
9Accepted3/3338ms5172 KiB
10Accepted2/2338ms5264 KiB
11Accepted2/2337ms5280 KiB
12Accepted2/2337ms5488 KiB
13Accepted2/2338ms5596 KiB
14Accepted2/2337ms5720 KiB
15Accepted2/2340ms5700 KiB
16Accepted2/2338ms5928 KiB
17Accepted2/2340ms5988 KiB
18Accepted2/2340ms6116 KiB
19Accepted2/2338ms6248 KiB
20Accepted3/3340ms6336 KiB
21Accepted3/3338ms6560 KiB
22Accepted3/3337ms6632 KiB
23Accepted3/3337ms6844 KiB