下面是题目复述:
You are given three integers , and .
Find two positive integers and (, ) such that:
the decimal representation of without leading zeroes consists of digits; the decimal representation of without leading zeroes consists of digits; the decimal representation of without leading zeroes consists of digits. denotes the greatest common divisor (GCD) of integers and .
Output
and . If there are multiple answers, output any of them.
Input
The first line contains a single integer () — the number of testcases.
Each of the next lines contains three integers , and (, ) — 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 — and (, ) such that
the decimal representation of without leading zeroes consists of digits;
the decimal representation of without leading zeroes consists of digits;
the decimal representation of without leading zeroes consists of digits.
Example
input
4
2 3 1
2 2 2
6 6 2
1 1 1
output
11 492
13 26
140133 160776
1 1
Note
In the example:
下面是解题思路:
题目大意:
输入三个数字a,b,c.
- a表示数字x的位数
- b表示数字y的位数
- c表示数字gcd(x,y)的位数。
(gcd(x,y)表示x和y的最大公约数)
求出满足条件的x和y,输出一组即可。
思路:
暴力枚举,把a位数下面的所有数字和b位数下面的的所有数字枚举求最大公约数,然后得到答案。
需要注意的是,pow很可能数据丢失精确度,可以提前打表确定几位数的开始数字。
下面是AC代码:
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
bool flag=false;
int gcd(int a,int b)
{
return b?gcd(b,a%b):a;
}
int bei[11];
void in()
{
bei[0]=1;
for(int i=1; i<10; i++)
bei[i]=bei[i-1]*10;
}
int main()
{
in();
int t;
scanf("%d",&t);
while (t--)
{
int a,b,c;
scanf("%d %d %d",&a,&b,&c);
for(int i=bei[a-1]; i<=bei[a]; i++)
{
for(int j=bei[b-1]; j<=bei[b]; j++)
{
int ans=gcd(i,j),num=0;
for(;ans>0;ans/=10) num++;
if(num==c)
{
printf("%d %d\n",i,j);
flag=true;
break;
}
}
if(flag) break;
}
}
return 0;
}