QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#466134 | #6440. Xingqiu's Joke | younger | TL | 0ms | 3648kb | C++20 | 1.4kb | 2024-07-07 16:16:57 | 2024-07-07 16:16:58 |
Judging History
answer
#include<iostream>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<vector>
#include<map>
#include<algorithm>
#include<queue>
#include <iomanip>
#define int long long
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
using namespace std;
typedef long long LL;
typedef __int128 i128;
typedef unsigned long long ULL;
typedef double db;
const int N = 1e5 + 10;
int a , b , cnt , p[N] , d , ans = 1e18;
map<pair<int , int> , bool>mp;
map<pair<int , int> , int>res;
int dfs(int a , int d){
int now = a - 1;
if(a == 0)return 1e18;
if(a == 1)return 0;
if(d == 1)return a - 1;
if(res[{a , d}])return res[{a , d}];
for(int i = 1 ; i <= cnt ; i ++){
if(d % p[i] == 0){
now = min({now , a % p[i] + 1 + dfs(a / p[i] , d / p[i]) , p[i] - a % p[i] + 1 + dfs(a / p[i] + 1 , d / p[i])});
}
}
// mp[{a , d}] = true;
return res[{a , d}] = now;
}
void Asuka()
{
cin >> a >> b;
if(a > b)swap(a , b);
d = b - a;
int x = d;
for(int i = 2 ; i * i <= x ; i ++){
if(x % i == 0){
p[++ cnt] = i;
}
while(x % i == 0){
x /= i;
}
}
if(x != 1)p[++ cnt] = x;
cout << dfs(a , d) << '\n';
return;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
cin >> t;
while(t --){
Asuka();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3648kb
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...