UVA 11889 Benefit

Source: Internet
Author: User

11889 Benefit

Test instructions

The T (t≤100000) group data is given, A,c (1≤a, c≤10e7) are given in each set of data, and the LCM (A, A, b) is known =c, the smallest

Output no solution if no solution is possible

Ideas:

More difficult to understand, you can think a few times. First b=c/a; if b is not int; Direct no solution, then loop (a value of GCD for a and B, then a/= value) until the value is 1;

Counter Example: 12 16 48, by the way This example analysis: b=c/a=48/12=4,12 and 4 of the LCM is 12 not 48 because they have gcd effect, and then gcd the value of the loop is 4, the answer 4*4


Recently Yaghoub is playing a new trick to sell some more. When somebody gives him A Tomans, he
Who never have appropriate changes, asks for B Tomans such that lowest common multiple of A and B
equals to C and he'll pay back a round bill. Or otherwise take some snack instead of the remaining of
He money. He believes that finding such a number are hard enough the dissuades students from paying
that.
You should write a program this help poor students giving the appropriate amount of
Yaghoub. Of course if there is several answers you go for students ' benefit which is the lowest of them.


Input
The first line begin with an integer T (t≤100000), the number of tests. Each test, comes in a
Separate line contains, integers A and C (1≤a, c≤107).


Output
Print the lowest integer B such the LCM (A, B) = C in A single line. If No such integer exists, print
' NO solution ' instead. (Quotes for clarity)


Sample Input
3
2 6
32 1760
7 16
Sample Output
3
55
NO Solution

The code is as follows:

1#include <iostream>2 3 using namespacestd;4 5 intgcdintMintN)6 {7     if(m<N)8     {9         intt=m;Tenm=N; Onen=T; A     } -     if(m%n==0) -         returnN; the     Else -         returnGCD (n,m%n); - } -  + intMain () - { +     intT; ACin>>T; at      while(t--) -     { -         inta,c; -Cin>>a>>C; -         if(c%a==0) -         { in             intb2=c/A; -             intcn1=1; to             inty=0; +              while(y!=1) -             { they=gcd (b2,a); *ans*=y; $A/=y;Panax Notoginseng             } -cout<<b2*ans<<Endl; the         } +         Else Acout<<"NO Solution"<<Endl; the     } +     return 0; -}

UVA 11889 Benefit

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.