QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#624592 | #6440. Xingqiu's Joke | wwww22# | WA | 700ms | 24424kb | C++20 | 2.9kb | 2024-10-09 16:11:34 | 2024-10-09 16:11:35 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define fo(i,a,b) for(ll (i)=(a);(i)<=(b);(i)++)
#define fd(i,a,b) for(ll (i)=(a);(i)>=(b);(i)--)
using namespace std;
const int N=2e5+10;
int n,a,b;
map<pair<int,int>,int> mp;
map<int,int>mm;
int vis[N];
int pr[N];
int cnt=0;
//ll gcd(ll a, ll b) {
// if (b == 0) return a;
// return gcd(b, a % b);
//}
//
//ll bmul(ll a, ll b, ll m) { // 快速乘
// ull c = (ull)a * (ull)b - (ull)((long double)a / m * b + 0.5L) * (ull)m;
// if (c < (ull)m) return c;
// return c + m;
//}
//
//ll qpow(ll x, ll p, ll mod) { // 快速幂
// ll ans = 1;
// while (p) {
// if (p & 1) ans = bmul(ans, x, mod);
// x = bmul(x, x, mod);
// p >>= 1;
// }
// return ans;
//}
//
//bool Miller_Rabin(ll p) { // 判断素数
// if (p < 2) return 0;
// if (p == 2) return 1;
// if (p == 3) return 1;
// ll d = p - 1, r = 0;
// while (!(d & 1)) ++r, d >>= 1; // 将d处理为奇数
// for (ll k = 0; k < 10; ++k) {
// ll a = rand() % (p - 2) + 2;
// ll x = qpow(a, d, p);
// if (x == 1 || x == p - 1) continue;
// for (int i = 0; i < r - 1; ++i) {
// x = bmul(x, x, p);
// if (x == p - 1) break;
// }
// if (x != p - 1) return 0;
// }
// return 1;
//}
//
//ll Pollard_Rho(ll x) {
// ll s = 0, t = 0;
// ll c = (ll)rand() % (x - 1) + 1;
// int step = 0, goal = 1;
// ll val = 1;
// for (goal = 1;; goal *= 2, s = t, val = 1) { // 倍增优化
// for (step = 1; step <= goal; ++step) {
// t = (bmul(t, t, x) + c) % x;
// val = bmul(val, abs(t - s), x);
// if ((step % 127) == 0) {
// ll d = gcd(val, x);
// if (d > 1) return d;
// }
// }
// ll d = gcd(val, x);
// if (d > 1) return d;
// }
//}
//
//void fac(ll x) {
// if (x <= max_factor || x < 2) return;
// if (Miller_Rabin(x)) { // 如果x为质数
// max_factor = max(max_factor, x); // 更新答案
// return;
// }
// ll p = x;
// while (p >= x) p = Pollard_Rho(x); // 使用该算法
// while ((x % p) == 0) x /= p;
// fac(x), fac(p); // 继续向下分解x和p
//}
int find(int a,int b)
{
int c=b;
int fa=2;
if(a<=0)return 1e9+10;
if(a==1)return 0;
if(b==1)return a-1;
if(mp.find(make_pair(a,b))!=mp.end()) return mp[make_pair(a,b)];
int ans=a-1;
while(c>1&&fa<c)
{
while(c%fa)
{
fa++;
if(fa*fa>c)
{
fa=c;
}
}
ans=min(ans,1+a%fa+find(a/fa,b/fa));
ans=min(ans,1+(fa-a%fa)+find(a/fa+1,b/fa));
c/=fa;
}
mp[make_pair(a,b)]=ans;
// cout<<a<<" "<<b<<" "<<ans<<"\n";
return ans;
}
void solve()
{
cin>>a>>b;
if(a>b)swap(a,b);
b=b-a;
cout<<find(a,b)<<"\n";
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
// init();
// for(int i=0;i<cnt;i++)
// {
// cout<<pr[i]*pr[i]<<" ";
// }
// cout<<"\n";
int T=1;
cin>>T;
while(T--) solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3676kb
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
Wrong Answer
time: 700ms
memory: 24424kb
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:
12 19 15 17 16 17 13 19 15 17 15 15 18 17 17 19 14 18 15 16 17 18 19 15 17 17 17 12 19 16 12 19 16 15 13 18 17 18 16 15 14 17 14 16 15 14 20 18 16 14 16 17 16 18 14 16 17 14 18 17 16 19 19 18 17 16 16 14 23 14 14 18 18 20 16 16 17 17 12 18 19 17 16 18 16 15 18 12 15 18 16 12 19 20 15 18 17 14 13 16 ...
result:
wrong answer 47th numbers differ - expected: '19', found: '20'