QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#553995 | #2755. Tightly Packed | Tenshi# | AC ✓ | 85ms | 3824kb | C++20 | 831b | 2024-09-09 01:16:38 | 2024-09-09 01:16:38 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define debug(x) cerr << #x << ": " << (x) << endl
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define dwn(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define x first
#define y second
using pii = pair<int, int>;
using ll = long long;
#define int ll
inline void read(int &x){
int s=0; x=1;
char ch=getchar();
while(ch<'0' || ch>'9') {if(ch=='-')x=-1;ch=getchar();}
while(ch>='0' && ch<='9') s=(s<<3)+(s<<1)+ch-'0',ch=getchar();
x*=s;
}
signed main(){
int n; cin>>n;
int l=sqrt(n/2);
int r=ceil(sqrt(n));
l=max(l, 1LL);
r=max(r, 1LL);
int res=1e18;
rep(b, l, r){
int a=(n+b-1)/b;
if(a>=b && a<=b*2 && a*b>=n) res=min(res, a*b-n);
}
cout<<res<<endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3772kb
input:
47
output:
1
result:
ok single line: '1'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3780kb
input:
523
output:
2
result:
ok single line: '2'
Test #3:
score: 0
Accepted
time: 3ms
memory: 3780kb
input:
10000000000001
output:
6
result:
ok single line: '6'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3692kb
input:
1
output:
0
result:
ok single line: '0'
Test #5:
score: 0
Accepted
time: 85ms
memory: 3824kb
input:
10000000000000000
output:
0
result:
ok single line: '0'
Test #6:
score: 0
Accepted
time: 30ms
memory: 3620kb
input:
1234567123459513
output:
35
result:
ok single line: '35'
Test #7:
score: 0
Accepted
time: 30ms
memory: 3696kb
input:
1234567123493710
output:
40
result:
ok single line: '40'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
1920
output:
0
result:
ok single line: '0'
Test #9:
score: 0
Accepted
time: 0ms
memory: 3752kb
input:
1921
output:
1
result:
ok single line: '1'
Test #10:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
1922
output:
0
result:
ok single line: '0'
Test #11:
score: 0
Accepted
time: 0ms
memory: 3692kb
input:
2
output:
0
result:
ok single line: '0'
Test #12:
score: 0
Accepted
time: 0ms
memory: 3700kb
input:
4803657
output:
43
result:
ok single line: '43'
Test #13:
score: 0
Accepted
time: 60ms
memory: 3776kb
input:
5000000000000104
output:
20
result:
ok single line: '20'
Test #14:
score: 0
Accepted
time: 0ms
memory: 3692kb
input:
526
output:
1
result:
ok single line: '1'
Test #15:
score: 0
Accepted
time: 0ms
memory: 3692kb
input:
8401
output:
14
result:
ok single line: '14'
Test #16:
score: 0
Accepted
time: 0ms
memory: 3720kb
input:
859615
output:
32
result:
ok single line: '32'
Test #17:
score: 0
Accepted
time: 84ms
memory: 3764kb
input:
9876543211288331
output:
52
result:
ok single line: '52'
Test #18:
score: 0
Accepted
time: 85ms
memory: 3772kb
input:
9999999999999761
output:
14
result:
ok single line: '14'