QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#409197 | #8111. Coaches | JohnAlfnov | WA | 1ms | 3916kb | C++20 | 1.2kb | 2024-05-11 20:22:35 | 2024-05-11 20:22:36 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int pan(int c,int a,int b,int d);
int nap(int c,int a,int b,int d);
long long panduan(int c,int a,int b,int d){
int A=a,C=c;
a%=b;c%=b;
if(c>=d)return C;
if(!a)return LLONG_MAX;
c=b-1-c;a=b-a;d=b-1-d;
int kk=pan(c,a,b,d);
if(kk==-1)return LLONG_MAX;
return C+1ll*kk*A;
}
int main(){
int T;
scanf("%d",&T);
while(T--){
long long n;
int a,b;
scanf("%lld%d%d",&n,&a,&b);
long long l=1ll*a*b/__gcd(a,b);
long long yc=n/a+n/b-2*(n/l);
int ra=n%a,rb=n%b;
long long rl=n%l;
int ys=(rl>min(ra,rb));
if(panduan(ra,a,b,rb)<rl)ys=2;
if(panduan(rb,b,a,ra)<rl)ys=2;
printf("%lld\n",n-yc+ys);
}
return 0;
}
int pan(int c,int a,int b,int d){
if(c<=d)return 0;
if(a==0)return -1;
if(2*a>b)return nap(b-1-c,b-a,b,b-1-d);
int k1=(b-c+a-1)/a,cc=(c+1ll*k1*a)%b;
int aa=(a-b%a)%a;
int cs=pan(cc,aa,a,d);
if(cs==-1)return -1;
int an=(b+a-1)/a*cs+k1-(cc+1ll*aa*cs)/a;
return an;
}
int nap(int c,int a,int b,int d){
if(c>=d)return 0;
if(a==0)return -1;
if(2*a>b)return pan(b-1-c,b-a,b,b-1-d);
int k1=(d-c+a-1)/a,cc=c+k1*a;
if(cc<b)return k1;
int cs=pan(cc-b+d+1,a,b,d);
if(cs==-1)return -1;
return cs+k1;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3912kb
input:
2 5 2 3 10 7 2
output:
3 6
result:
ok 2 number(s): "3 6"
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3916kb
input:
1728 7 6 3 10 12 1 6 2 7 8 4 10 11 10 5 1 6 8 3 3 5 9 2 6 11 1 5 1 1 8 7 3 6 6 10 9 2 1 7 3 4 7 8 3 4 4 5 9 9 4 3 6 2 8 11 4 1 6 8 4 11 1 8 9 11 2 9 6 1 5 3 8 7 1 8 7 11 12 3 9 1 2 12 6 7 2 6 5 11 10 9 5 3 3 6 2 7 5 5 12 4 3 7 8 2 8 11 11 10 1 10 5 1 7 9 1 7 8 1 6 8 4 6 5 5 11 12 3 7 3 6 8 6 3 11 6 ...
output:
6 1 4 7 10 1 3 7 3 1 6 6 1 3 6 4 6 4 3 6 2 6 2 5 1 7 1 2 5 5 7 3 7 7 5 8 1 1 2 2 7 5 9 3 5 4 11 3 1 1 12 3 7 1 5 5 12 2 10 1 9 5 1 2 10 6 3 12 1 12 10 6 1 7 2 5 10 7 11 9 2 3 1 6 9 8 2 5 3 3 10 1 9 11 2 8 8 7 7 9 3 1 2 3 1 3 3 9 4 6 8 1 12 6 3 10 1 1 9 12 6 1 9 11 1 6 2 3 12 7 6 6 9 11 9 1 2 5 2 4 4...
result:
wrong answer 233rd numbers differ - expected: '5', found: '6'