QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#47252 | #1175. Bags of Candies | Gemini7X | TL | 16ms | 5692kb | C++14 | 992b | 2022-09-06 17:16:06 | 2022-09-06 17:16:08 |
Judging History
answer
/*
author : Gemini
date : September 6th, 2022
url : https://vjudge.net/contest/512482#problem/I
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=316305;
template<typename T>
void read(T &x){
T sgn=1;
char ch=getchar();
for(;!isdigit(ch);ch=getchar())if(ch=='-')sgn=-1;
for(x=0;isdigit(ch);ch=getchar())x=x*10+ch-'0';
x*=sgn;
}
ll g[maxn<<1],a[maxn<<1];
int sq,tot,cnt;
ll F(ll n){
cnt=tot=0;
sq=sqrt(n);
for(ll i=1;i<=n;i=a[tot]+1){
a[++tot]=n/(n/i);
g[tot]=a[tot]-1;
}
auto id=[n](ll x){
return x<=sq?x:tot-n/x+1;
};
for(int i=2;i<=sq;i++){
if(g[i]!=g[i-1]){
cnt++;
for(int j=tot;a[j]>=1ll*i*i;j--){
g[j]-=g[id(a[j]/i)]-cnt+1;
}
}
}
return g[tot];
}
int main(){
int T;
read(T);
while(T--){
ll n;
read(n);
if(n==1){
puts("1");
}else if(n==2){
puts("2");
}else{
ll num=F(n)-F(n/2)+1;
printf("%lld\n",(n-num+1)/2+num);
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5688kb
input:
2 4 9
output:
3 6
result:
ok 2 number(s): "3 6"
Test #2:
score: 0
Accepted
time: 3ms
memory: 5600kb
input:
5 2 3 4 5 6
output:
2 3 3 4 4
result:
ok 5 number(s): "2 3 3 4 4"
Test #3:
score: 0
Accepted
time: 3ms
memory: 5692kb
input:
5 1111 2018 3333 4006 5555
output:
599 1078 1772 2128 2942
result:
ok 5 number(s): "599 1078 1772 2128 2942"
Test #4:
score: 0
Accepted
time: 16ms
memory: 5680kb
input:
5 26666666 10000000 23456789 27777777 24444442
output:
13730373 5158034 12080298 14301448 12588059
result:
ok 5 number(s): "13730373 5158034 12080298 14301448 12588059"
Test #5:
score: -100
Time Limit Exceeded
input:
5 47890123456 12345678901 96666666669 85555555558 100000000000