-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalice.cpp
More file actions
executable file
·42 lines (39 loc) · 767 Bytes
/
alice.cpp
File metadata and controls
executable file
·42 lines (39 loc) · 767 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
long unsigned int gcd(long unsigned int u, unsigned int v)
{
long unsigned int shift;
if (u == 0) return v;
if (v == 0) return u;
for (shift = 0; ((u | v) & 1) == 0; ++shift) {
u >>= 1;
v >>= 1;
}
while ((u & 1) == 0)
u >>= 1;
do {
while ((v & 1) == 0)
v >>= 1;
if (u > v) {
unsigned int t = v; v = u; u = t;}
v = v - u;
} while (v != 0);
return u << shift;
}
int main()
{
long unsigned int t,m,n,y,z,x;
scanf("%ld",&t);
while(t>0)
{
scanf("%lu %lu",&n,&m);
z=m*n;
y=((n+1)/2)*(m/2);
x=gcd(y,z);
printf("%lu %lu %lu\n",z,y,x);
printf("%lu/%lu\n",y/x,z/x);
t--;
}
return 0;
}