有一个直线赛道,两位运动员每步跑的都是整数,现在在某个地方之后挖一个大坑,运动员会在下一步要踩到之前停下,这时候判断胜者,问有多少几率他们会平局;
解题思路:
最小公倍数一定是平局,然后每一个平局后也都会有一段平局,长度等于,n,m中小的那个数-1;
大数;直接用Java过了;
代码:
import java.math.*;
import java.util.Scanner;;
public class cal {
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
BigInteger t,w,b;
t=scan.nextBigInteger();
w=scan.nextBigInteger();
b=scan.nextBigInteger();
if(w.compareTo(b)>0)
{
BigInteger temp=w;
w=b;
b=temp;
}
BigInteger temp1=t.mod(w.multiply(b).divide(w.gcd(b)));
if(temp1.compareTo(w.subtract(BigInteger.ONE))>0)
temp1=w.subtract(BigInteger.ONE);
BigInteger num=t.divide(w.multiply(b).divide(w.gcd(b)));
BigInteger x=w.multiply(num).add(temp1);
BigInteger i=x.divide(x.gcd(t));
BigInteger j=t.divide(x.gcd(t));
System.out.println(i+"/"+j);
}
}