QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#666020#6440. Xingqiu's Jokecomp_towels_catTL 0ms3612kbC++173.4kb2024-10-22 16:18:512024-10-22 16:18:53

Judging History

你现在查看的是最新测评结果

  • [2024-10-22 16:18:53]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3612kb
  • [2024-10-22 16:18:51]
  • 提交

answer

#pragma GCC optimize(2)
#pragma GCC optimize(3,"Ofast","inline")
#include <bits/stdc++.h>
#define int long long
#define FOR(i, j, k) for(int i = (j);i <= (k);i ++)
#define ROF(i, j, k) for(int i = (j);i >= (k);i --)
#define For(i, j, k) for(int i = (j);i < (k);i ++)
#define Rof(i, j, k) for(int i = (j);i > (k);i --)
#define ull unsigned long long
#define PII pair<int,int>
#define ULL unsigned long long
#define db double
#define x first
#define y second
#define sp(x) fixed << setprecision(x)
#define all(x) x.begin(), x.end()
#define unq_all(x) x.erase(unique(all(x)), x.end())
#define M(x) x %= mod, x += mod, x %= mod
#define YES cout << "YES\n"
#define NO cout << "NO\n"
#define Yes cout << "Yes\n"
#define No cout << "No\n"
#define ANS cout << ans << '\n'
#define de(p) cout << #p << ' ' << p << '\n'
#define END(i, n) (i == n ? '\n' : ' ')
#define double long double

#define RED cout << "\033[91m"
#define GREEN cout << "\033[92m"
#define YELLOW cout << "\033[93m"
#define BLUE cout << "\033[94m"
#define MAGENTA cout << "\033[95m"
#define CYAN cout << "\033[96m"
#define RESET cout << "\033[0m"

// 红色
#define DEBUG1(x)                     \
    RED;                              \
    cout << #x << " : " << x << endl; \
    RESET;

// 绿色
#define DEBUG2(x)                     \
    GREEN;                            \
    cout << #x << " : " << x << endl; \
    RESET;

// 蓝色
#define DEBUG3(x)                     \
    BLUE;                             \
    cout << #x << " : " << x << endl; \
    RESET;

// 品红
#define DEBUG4(x)                     \
    MAGENTA;                          \
    cout << #x << " : " << x << endl; \
    RESET;

// 青色
#define DEBUG5(x)                     \
    CYAN;                             \
    cout << #x << " : " << x << endl; \
    RESET;

// 黄色
#define DEBUG6(x)                     \
    YELLOW;                           \
    cout << #x << " : " << x << endl; \
    RESET;


using namespace std;


const int N = 1e6 + 10, M = N * 2, INF = 1e9, mod = 998244353;

int n, m, k;
int a,b;
int ans = 0;
map<PII,int> mp;
int P[N];

int get(int x,int dlt)
{
    if (x == 1)
    {
        return 0;
    }
    else if (dlt == 1)
    {
        return x - 1;
    }
    if (mp.find({x,dlt + x}) != mp.end()) return mp[{x,dlt + x}];
    mp[{x,x + dlt}] = x - 1;
    FOR(j,1,n)
    {
        int i = P[j];
        if (dlt % i == 0)
        {
            int res = x % i;
            mp[{x,x + dlt}] = min({mp[{x,x + dlt}],get(x / i,dlt / i) + res + 1,get(x / i + 1,dlt / i + 1) + i - res + 1});
        }
    }
    return mp[{x,x + dlt}];
}

void solve()
{
    cin >> a >> b;
    if (a > b) swap(a,b);
    int dlt = b - a;

    n = 0;
    int res = dlt;
    FOR(i,2,res / i)
    {
        if (res % i == 0)
        {
            P[++n] = i;
            while (res % i == 0)
            {
                res /= i;
            }
        }
    }
    if (res != 1) P[++n] = res;
//    ans = min(ans,get(a,dlt));
    cout << get(a,dlt) << '\n';
}

signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    auto t = clock();
    int T = 1;
    cin >> T;
    while (T--)
    {
        solve();
    }
    auto tt = clock();

//    cout << "Time: " << 1000.0 * (tt - t) / CLOCKS_PER_SEC << "ms" << endl;
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3612kb

input:

5
4 7
9 8
32 84
11 35
2 1

output:

2
7
5
4
0

result:

ok 5 number(s): "2 7 5 4 0"

Test #2:

score: -100
Time Limit Exceeded

input:

300
223528529 446621399
755625805 978718675
257717538 480810408
277875777 54782907
963091558 739998688
282469431 505562301
38752451 261845321
474429597 697522467
67026335 290119205
874629705 651536835
301964126 78871256
316864911 93772041
545942587 322849717
640801578 417708708
683070559 906163429
9...

output:


result: