Loading

Educational Codeforces Round 107 (Rated for Div. 2) B. GCD Length(思维/构造/最大公因数)

You are given three integers a, 𝑏b and c.

Find two positive integers x and y (x>0, y>0) such that:

  • the decimal representation of x without leading zeroes consists of a digits;
  • the decimal representation of y without leading zeroes consists of b digits;
  • the decimal representation of gcd(x,y) without leading zeroes consists of c digits.

gcd(x,y) denotes the greatest common divisor (GCD) of integers x and y.

Output x and y. If there are multiple answers, output any of them.

Input

The first line contains a single integer t (1≤t≤285) — the number of testcases.

Each of the next 𝑡t lines contains three integers a, b and c (1≤a,b≤9, 1≤c≤min(a,b)) — the required lengths of the numbers.

It can be shown that the answer exists for all testcases under the given constraints.

Additional constraint on the input: all testcases are different.

Output

For each testcase print two positive integers — 𝑥x and 𝑦y (x>0, y>0) such that

  • the decimal representation of 𝑥x without leading zeroes consists of a digits;
  • the decimal representation of 𝑦y without leading zeroes consists of b digits;
  • the decimal representation of gcd(x,y) without leading zeroes consists of c digits.

Example

input

Copy

4
2 3 1
2 2 2
6 6 2
1 1 1

output

Copy

11 492
13 26
140133 160776
1 1

大意就是构造长度为a,b,c的三个数使得最后一个数是前两个数的gcd。

首先特判两组情况:

c = 1时,直接构造\(10^{a - 1}, 10^{b - 1} + 1\),他们的gcd必然为1(设gcd为k,则k必须满足\(k|10^{a - 1},k|(10^{b - 1}+1)\),故k只能为1)。

a == c或者b == c时,直接构造\(10^{a - 1}, 10^{b - 1}\),这就相当于一个数是另一个数的倍数,那么他们的gcd一定是比较小的那个数。

对于其他情况,首先算出来a与c的差值d1以及b与c的差值d2,然后构造\(10^{c-1}\times10^{d1},10^{c-1}\times(10^{d2}+1)\),由于\(gcd(10^{d1}, 10^{d2}+1)=1\),因此构造出来的两个数的gcd即为长度为c的\(10^{c-1}\)

构造的思路大概就是参考相邻奇数偶数的gcd为1这样..(雾

#include <bits/stdc++.h>
using namespace std;
int fpow(int a, int b){
	int ans = 1;
	for(; b; b >>= 1) {
		if(b & 1) ans = ans * a;
		a = a * a;
	}
	return ans;
}
int gcd(int a, int b) {
	return b ? gcd(b, a % b) : a;
}
int main() {
	int t;
	cin >> t;
	while(t--) {
		int a, b, c;
		cin >> a >> b >> c;
		if(c == 1) {
			cout << fpow(10, a - 1) << ' ' << fpow(10, b - 1) + 1 << endl;
			continue;
		} 
		else if(a == c || b == c) {
			cout << fpow(10, a - 1) << ' ' << fpow(10, b - 1) << endl;
			continue;
		}
		int d1 = a - c, d2 = b - c;
		cout << fpow(10, c - 1) * (fpow(10, d1)) << ' ' << fpow(10, c - 1) * (fpow(10, d2) + 1) << endl;
	}
	return 0;
}
posted @ 2021-04-14 14:27  脂环  阅读(150)  评论(0)    收藏  举报