Advertisement
Saleh127

LO 1215

Sep 30th, 2020
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
  5. int main()
  6. {
  7. ios_base::sync_with_stdio(0);
  8. cin.tie(0);cout.tie(0);
  9.  
  10. test
  11. {
  12. ll a,v,c,d,e,f,i,j,k,l;
  13. cin>>a>>v>>l;
  14. d=(a*v)/__gcd(a,v); //d is the greatest common divisor of a and v
  15.  
  16. cout<<"Case "<<cs<<": ";
  17.  
  18. if(l%d)
  19. {
  20. cout<<"impossible"<<endl;
  21. }
  22. else
  23. {
  24. ///To make lcm (d, e) = de, there must be at least a prime factor in l that is not in d and an index in l that is greater than d in the index taken in l
  25. ///C now contains the prime factors in l that are not in m take the exponent in l and the exponent in l is greater than the prime factor in m take the exponent difference
  26. ///So now e still needs to be multiplied by the common prime factors of e and d to take the exponent in d
  27. ///gcd (d, e) takes the small exponential product of e and d common prime factors
  28. e=l/d;
  29.  
  30. f=__gcd(e,d);
  31. while(f!=1)
  32. {
  33. e*=f;
  34. d/=f;
  35. f=__gcd(e,d);
  36. }
  37. cout<<e<<endl;
  38. }
  39. }
  40. return 0;
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement