#include<iostream>
using namespace std;
#define lli long long int
lli gcd(lli a, lli b)
{
if(b == 0)
return a;
else
return gcd(b, a%b);
}
lli lcm(lli a, lli b)
{
return (a/gcd(a, b)) * b;
}
int main()
{
lli a, b, l, g, k, r, t, c = 1;
cin >> t;
while(t--)
{
cin >> a >> b >> l;
cout << "Case " << c++ << ": ";
k = lcm(a, b);
if(l%k != 0)
cout << "impossible" << endl;
else
{
r = l/k;
while(1)
{
g = gcd(k, r);
if(g == 1)
break;
r = r * g;
k = k/g;
}
cout << r << endl;
}
}
return 0;
}
using namespace std;
#define lli long long int
lli gcd(lli a, lli b)
{
if(b == 0)
return a;
else
return gcd(b, a%b);
}
lli lcm(lli a, lli b)
{
return (a/gcd(a, b)) * b;
}
int main()
{
lli a, b, l, g, k, r, t, c = 1;
cin >> t;
while(t--)
{
cin >> a >> b >> l;
cout << "Case " << c++ << ": ";
k = lcm(a, b);
if(l%k != 0)
cout << "impossible" << endl;
else
{
r = l/k;
while(1)
{
g = gcd(k, r);
if(g == 1)
break;
r = r * g;
k = k/g;
}
cout << r << endl;
}
}
return 0;
}
Comments
Post a Comment