QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#424921 | #8111. Coaches | ffffyc | RE | 0ms | 0kb | C++14 | 1.5kb | 2024-05-29 19:54:52 | 2024-05-29 19:54:53 |
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lll __int128
namespace IO{//by cyffff
int len=0;
char ibuf[(1<<21)+1],*iS,*iT,out[(1<<25)+1];
#if ONLINE_JUDGE
#define gh() (iS==iT?iT=(iS=ibuf)+fread(ibuf,1,(1<<21)+1,stdin),(iS==iT?EOF:*iS++):*iS++)
#else
#define gh() getchar()
#endif
#define reg register
inline ll read(){
reg char ch=gh();
reg ll x=0;
reg char t=0;
while(ch<'0'||ch>'9') t|=ch=='-',ch=gh();
while(ch>='0'&&ch<='9') x=x*10+(ch^48),ch=gh();
return t?-x:x;
}
inline void putc(char ch){
out[len++]=ch;
}
template<class T>
inline void write(T x){
if(x<0)putc('-'),x=-x;
if(x>9)write(x/10);
out[len++]=x%10+48;
}
inline void flush(){
fwrite(out,1,len,stdout);
len=0;
}
inline char getc(){
char ch=gh();
while(ch<'A'||ch>'Z') ch=gh();
return ch;
}
}
using IO::read;
using IO::write;
using IO::flush;
using IO::getc;
using IO::putc;
int T;
ll n,a,b,c,a1,b1;
inline bool check(ll n,ll a,ll b){
ll al=b/a*a;
if(n<al) return 0;
if(n%b<al) return 1;
return check(n/b*(b%a)+n%b-al,b%a,a);
}
int main(){
// system("fc ex_xor2.out ex_xor2.ans");
freopen("xor.in","r",stdin);
freopen("xor.out","w",stdout);
T=read();
while(T--){
n=read(),a=read(),b=read();
if(a>b) swap(a,b);
int d=__gcd(a,b);
c=a*b/d,a1=a/d,b1=b/d;
ll t=n-n/a-n/b+n/c*2;
if(n%c<a) write(t);
else write(t+1+check(n%c/d,a1,b1));
putc('\n');
}
flush();
}
/*
1
304432168 9893 11664
*/
详细
Test #1:
score: 0
Dangerous Syscalls
input:
2 5 2 3 10 7 2