链接:https://ac.nowcoder.com/acm/contest/885/A
来源:牛客网
You are given a positive integer n which is at most 100.
Please find a positive integer satisfying the following conditions:
1. The sum of all digits of this number is dividable by n.
2. This number is also dividable by n.
3. This number contains no more than 10410^4104 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≤1001 \le T \le 1001≤T≤100 * 1≤n≤1001 \le n \le 1001≤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).
这题就很坑,给的测试样例我还真要看看题解是怎么求的
这题开始想的是用各个进制上求%打表做,直到明白位数是1e4(大),就很难受。
他给你n,假设是19好吧,那我求出来的是最少几个19连在一起满足条件(各个位置和被19,这个值因为是k个19连在一起,所以定能被19整除)就完事了(这里19是用各个位数和判断,把和扩大倍数,不成立是判断位数满足小于1e4,否则就无解),Giao
#include<bits/stdc++.h>
using namespace std;
const int inf = 10000;
int getsum(int x){
int sum=0;
while(x){
sum+=(x%10);
x/=10;
}
return sum;
}
int getbit(int x){
int bit=0;
while(x){
bit++;
x/=10;
}
return bit;
}
int main(){
int t;cin>>t;
while(t--){
int n;scanf("%d",&n);
int m = getsum(n);
int k=0;
for(int i=2;i<inf;i++){
if(i*m%n==0){
k=i;
break;
}
}
if(k==0|| k*getbit(n)>inf){
printf("Impossible\n");
continue;
}
for(int i=0;i<k;i++){
cout<<n;
}
cout<<endl;
}
return 0;
}