(LCM (a, B) = C; C is the smallest common multiple of A and B. Now we have a and c. You need to find the smallest B.
Solution:
1. If C %! = 0 indicates no solution. Set B = C/A. When gcd (a, B) = 1, B indicates that B is the required result. If gcd (a, B )! = 1;
Then, lcm (a, B) must be smaller than C. Why do you think about this? Because some of the original results of a are the same as those of Result B?
A affects the value of B.
2. example: A = 12 = 2 ^ 2*3 ^ 1, B = 16 = 2 ^ 4, C = 48 = 2 ^ 4*3 ^ 1; B '= C/a = 4 = 2 ^ 2;
If B 'is the part of B that is different from a, then we obtain B' if gcd (A, B ')! = 1 indicates that a partially affects the result.
In this way, we need B '* gcd (A, B'), a/gcd (A, B '), and know that gcd (, B ') = 1.
Then B 'gets the original Result B.
// Excerpt from http://blog.sina.com.cn/s/blog_77dc9e080101jhq7.html
PS: the code is customized... Orz
# Include <iostream>
Using namespace STD;
Int A, C, B;
Int gcd (int A, int B ){
Return B = 0? A: gcd (B, A % B );
}
Int main (){
Int T;
Cin> T;
While (t --){
Cin> A> C;
If (C % A = 0 ){
B = C/;
Int D;
D = gcd (A, B );
While (D! = 1 ){
B * = D;
A/= D;
D = gcd (A, B );
}
Cout <B <Endl;
}
Else
Cout <"no solution" <Endl;
}
Return 0;
}