本文共 1848 字,大约阅读时间需要 6 分钟。
31000000000 1 18 2 411 5 3
08 16 long long gcd(long long a,long long b){ return b==0?a:gcd(b,a%b);}int main(){ int t; cin>>t; while(t--) { long long n,a,b; scanf("%lld%lld%lld",&n,&a,&b); long long ans = 0; long long e = a/gcd(a,b)*b; long long ti = n/e; long long ty = n%e; long long now=0; long long tmp; long long x=0,y=0; while(nowe) tmp=e-now; ans+=tmp*abs(x-y); x=(x+tmp)%a; y=(y+tmp)%b; now+=tmp; } ans*=ti; now = 0; x = 0; y = 0; while(now ty) tmp=ty-now; ans+=tmp*abs(x-y); x=(x+tmp)%a; y=(y+tmp)%b; now+=tmp; } cout< <
转载地址:http://cvali.baihongyu.com/