CPP0173 - CHIA HET CHO BA SO NGUYEN

 avatar
unknown
plain_text
4 years ago
639 B
4
Indexable
#include<iostream>
#include<math.h>

using namespace std;

long long GCD(long long a, long long b){
	while(a != b){
		if(a > b) a = a - b;
		else b = b - a;
	}
	return a;
}

int main(){
	int t;
	cin >> t;
	long long x, y, z, n;
	while(t--){
		cin >> x >> y >> z >> n;
		
		int bc1 = (x * y) / GCD(x, y);
		int bc2 = (bc1 * z) / GCD(bc1, z);
		long long start = pow(10, n-1), end = pow(10,n);
		
		long long answer;
		if(start % bc2 == 0) answer = bc2 * start / bc2;
		else answer = bc2 * (1 + (long long)start/bc2);
		if(answer >= start && answer < end) cout << answer << endl;
		else cout << -1 << endl;
	}
}
Editor is loading...