Digitis
链接:https://ac.nowcoder.com/acm/contest/885/A
Problem description
You are given a positive integer n which is at most 100.
Please find a positive integer satisfying the following conditions:
-
The sum of all digits of this number is dividable by n.
-
This number is also dividable by n.
-
This number contains no more than 104 digits.
If such an integer doesn’t exist, output “Impossible” (without quotation marks).
If there are multiple such integers, please output any one.
输入描述:
The first line contains one integer T indicating that there are T tests.
Each test consists an integer n in a single line.
-
1≤T≤100
-
1≤n≤100
输出描述:
For each query, output one line containing the answer. The number you print cannot have leading zeros. If there are multiple answers, you can print any. If such an integer doesn’t exist, output “Impossible” (without quotation marks) in a single line.
示例1
输入
3
1
9
12
输出
1
666666
888
说明
For the last test, 888 is dividable by 12 (888 = 12 * 74) and 8 + 8 + 8 = 24 is also dividable by 12 (24 = 12 * 2).
题意
对于给出的数字 n ,输出一个数,这个数既能整除 n ,它的各位数字加和也能够整除 n
分析
- 要输出一个数,能够整除 n , 则输出这个数 n 次,它本身的每一次输出就是 n 的倍数
- 输出一个数 n 次,那么其加和一定是 n * x ( x是原数加和的结果 ),所以一定可以被整除
代码
#include<bits/stdc++>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
int n;
cin>>n;
for(int i=0;i<n;i++) cout<<n;
cout<<endl;
}
return 0;
}