Advertisement
anhkiet2507

CHIA HET CHO BA SO NGUYEN - AC

Sep 1st, 2021
2,267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. using namespace std;
  4. long long UCLN(long long a, long long b){
  5.     if(b==0){
  6.         return a;
  7. } else {
  8.     return UCLN(b,a%b);
  9. }
  10. }
  11. long long BCNN(long long a, long long b){
  12.     return (a*b/UCLN(a,b) );
  13. }
  14. int main(){
  15.     long long x,y,z,m,ti,n;
  16.     cin>>m;
  17.     while (m--){
  18.         cin>>x>>y>>z>>n;
  19.         ti=BCNN(x,y);
  20.         ti=BCNN(ti,z);
  21.         n=pow(10,n-1);
  22.         if ((ti/n)>9){
  23.             cout<<"-1"<<endl;
  24.         } else {
  25.             if (ti>=n){
  26.                 cout<<ti<<endl;
  27.             }else{
  28.                 if ((n%ti)==0){
  29.                     cout<<ti*((n/ti))<<endl;
  30.                 }else{
  31.                     cout<<ti*((n/ti)+1)<<endl;
  32.                 }
  33.             }
  34.         }
  35.     }
  36.    
  37.     return 0;
  38. }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement