QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#545521 | #4366. Forever Young | PhantomThreshold# | WA | 52ms | 3732kb | C++20 | 1.6kb | 2024-09-03 14:36:34 | 2024-09-03 14:36:35 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll sq(ll x){
ll sz=sqrtl(x);
for (;(sz+1)*(sz+1)<=x;) sz++;
for (;sz*sz>x;) sz--;
return sz;
}
pair<ll,ll> solve(ll a,ll b,ll c){
if (a==0){
if (c%b!=0) return make_pair(-1LL,-1LL);
return make_pair(-1LL,-c/b);
}
ll delta=b*b-4*a*c;
if (delta<0) return make_pair(-1LL,-1LL);
ll sqdt=sq(delta);
if (sqdt*sqdt!=delta) return make_pair(-1LL,-1LL);
ll x1=-b-sqdt;
ll x2=-b+sqdt;
if (x1%(2*a)!=0) x1=-1;
else x1=x1/(2*a);
if (x2%(2*a)!=0) x2=-1;
else x2=x2/(2*a);
return make_pair(x1,x2);
}
ll y,l;
int main(){
cin >> y >> l;
ll ans=10;
for (ll b=11;b<=1000000;b++){
vector<ll> digit;
for (ll now=y;now;now/=b) digit.push_back(now%b);
bool flag=1;
ll res=0;
reverse(digit.begin(),digit.end());
for (auto x:digit){
if (x>9){
flag=0;
break;
}
res=res*10+x;
}
if (!flag) continue;
// cerr << b << " " << res << endl;
if (res>=l) ans=max(ans,b);
}
// cerr << "ans : " << ans << endl;
for (ll a=0;a<=9;a++){
for (ll b=0;b<=9;b++){
for (ll c=0;c<=9;c++){
if (a*100+b*10+c<l) continue;
auto [x1,x2]=solve(a,b,c-y);
if (x1>0) ans=max(ans,x1);
if (x2>0) ans=max(ans,x2);
}
}
}
cout << ans << "\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 14ms
memory: 3564kb
input:
32 20
output:
16
result:
ok single line: '16'
Test #2:
score: 0
Accepted
time: 14ms
memory: 3500kb
input:
2016 100
output:
42
result:
ok single line: '42'
Test #3:
score: 0
Accepted
time: 52ms
memory: 3716kb
input:
1000000000000000000 10
output:
1000000000000000000
result:
ok single line: '1000000000000000000'
Test #4:
score: 0
Accepted
time: 49ms
memory: 3576kb
input:
149239876439186 470
output:
11
result:
ok single line: '11'
Test #5:
score: 0
Accepted
time: 32ms
memory: 3732kb
input:
4851495 95
output:
539054
result:
ok single line: '539054'
Test #6:
score: 0
Accepted
time: 31ms
memory: 3528kb
input:
19839853985 19839853985
output:
10
result:
ok single line: '10'
Test #7:
score: 0
Accepted
time: 51ms
memory: 3576kb
input:
1000000000000000000 17
output:
999999999999999993
result:
ok single line: '999999999999999993'
Test #8:
score: 0
Accepted
time: 51ms
memory: 3580kb
input:
1000000000000000000 23
output:
499999999999999998
result:
ok single line: '499999999999999998'
Test #9:
score: 0
Accepted
time: 51ms
memory: 3576kb
input:
1000000000000000000 58
output:
166666666666666666
result:
ok single line: '166666666666666666'
Test #10:
score: 0
Accepted
time: 48ms
memory: 3564kb
input:
1000000000000000000 145
output:
999999997
result:
ok single line: '999999997'
Test #11:
score: -100
Wrong Answer
time: 52ms
memory: 3728kb
input:
1000000000000000000 230
output:
1000000
result:
wrong answer 1st lines differ - expected: '500000000', found: '1000000'