For those who don’t speak Chinese, huashui may not even be a legitimate word for you. You don’t have
to know what it is to solve this problem, but to make everything clear, huashui refers to the status of
not working, especially at working hours.
Some people decide to make some plans on when to work, and when to huashui. So they invent a lockscreen app with a built-in clock. This clock is just like any other usual clock, except that it has h hours a day and m minutes an hour. Indicator of seconds is not displayed in the app, so you can safely ignore that. Therefore the time display ranges from “0 : 0” to “h−1 :m−1”. Well, the plan works like this: if the minute number is greater than or equal to the hour number, this minute is a “huashui minute”; otherwise you are going to work.
You are a hard-worker, and you probably disdain the idea of this clock; but Donald, as a huashui-lover, is obsessed with this app and would very much like to know how much time in a day he can huashui. Help him calculate that and you will win a balloon
nput
The only line of the input consists of two integers h and m(2≤h, m≤109), with space between
Output
Output huashui time divided by the length of time in a day in a reduced fraction form.
standard input
standard output
2 2
3/4
2 7
13/14
7 2
3/14
13 11
6/13
100 33
17/100
100005 100009
50007/100009
1000000000 2
3/2000000000
2 999999999
1999999997/1999999998
914067307 998244353
541210700/998244353
#include<stdio.h>
#include<math.h>
int main()
{
long long h, i,m, x, y, max, min, d, k;
scanf("%lld %lld", &h, &m);
if(h <= m)
{
x = h * m +(h*(h-1)*(-1))/2;
}
else
{
x = ((m+1)*m) / 2;
}
y = h * m;
max = y;
min = x;
while(max != 0)//求最大公因数 辗转相除法
{
d = max % min;
if(d == 0)
{
k = min;
break;
}
else
{
max = min;
min = d;
}
}
x=x/k;y=y/k;
printf("%lld/%lld\n", x, y);
return 0;
}
最大公约数
a,b为正整数(a>b)
(a,b)表示a,b的最大公约数
商q和余r数满足a=bq+r,且0≤r ≤b-1. 若r=0,显然(a,b)=b;若r≠0,由于a=bq+r,每个能整除b,r的整数都能整除a,当然能同时整除a,b,所以(b,r)|(a,b);另一方面,r=a-bq,每个能整除a,b的整数都能整除r, 当然能同时整除b,r, 所以(a,b)|(b,r).因此(a,b)=(b,r). 辗转相除法进行一步后,b 取代原来的a,用r取代原来的b,最大公约数保持不变