Advertisement
anhkiet2507

CHIAHETCHO3SONGUYEN

Aug 24th, 2021
2,598
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <iomanip>
  4. using namespace std;
  5. long long UCLN(long long a, long long b){
  6.     if(b==0){
  7.         return a;
  8.     }else{
  9.         return UCLN(b,a%b);
  10.     }
  11. }
  12. long long BCNN(long long a, long long b){
  13.     return(a*b/UCLN(a,b));
  14. }
  15. long long SCS(long long n){
  16.     long long scs=0;
  17.     while(n>0){
  18.         n = n/10;
  19.         scs++;
  20.     }
  21.     return scs;
  22. }
  23. int main() {
  24.     int t;
  25.     cin >> t;
  26.     while(t--){
  27.         long long x, y, z , n;
  28.         cin >> x;
  29.         cin >> y;
  30.         cin >> z;
  31.         cin >> n;
  32.         long long boichung = BCNN(BCNN(x,y),z);
  33.         if(SCS(boichung)>n){
  34.             cout << -1 << endl;
  35.         }else{
  36.             if(SCS(boichung)==n){
  37.                 cout << boichung << endl;
  38.             } else {
  39.                 long long sodautien=pow(10,n-1);
  40.                 long long sodu = sodautien % boichung;
  41.                 long long ketqua = sodautien + (boichung - sodu);
  42.                 cout << ketqua << endl;            
  43.             }
  44.  
  45.         }
  46.        
  47.     }
  48.     return 0;
  49. }
  50.  
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement