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时,直接构造10a1,10b1+1,他们的gcd必然为1(设gcd为k,则k必须满足k|10a1k|(10b1+1),故k只能为1)。

a == c或者b == c时,直接构造10a1,10b1,这就相当于一个数是另一个数的倍数,那么他们的gcd一定是比较小的那个数。

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

构造的思路大概就是参考相邻奇数偶数的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 @   脂环  阅读(132)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
历史上的今天:
2020-04-14 Codeforces Round #634 E2. Three Blocks Palindrome (hard version)(双指针/前缀和/二分/好题)
2020-04-14 Codeforces Round #634 D. Anti-Sudoku(构造/水)
2020-04-14 Codeforces Round #634 C. Two Teams Composing(排序)
2020-04-14 Codeforces Round #634 B. Construct the String(贪心)
2020-04-14 Codeforces Round #634 A. Candies and Two Sisters(水)
点击右上角即可分享
微信分享提示
主题色彩