Problem C: Number Gun
Description:
MN wants to kill some numbers with number gun. A number gun can kill its factors. For example, 14 can kill 2 and 7. A gun X is 0 at the begining, when"JTH" finds that the number gun can’t kill the aim number, he will add a digital to the end of the gun in order “1234567890123…”.
For example, “JTH” wants to kill 3, the gun is 0 at the begining, he finds that 0 can’t kill 3, he adds 1 to the last of the gun, the gun becomes “01”, and “01” can’t kill 3, he adds 2 to the last , the gun becomes “012”. 12 % 3 == 0. The gun can kill 3.
MN wants to know the length of the gun when the first time he can kill the aim number.
Input:
Multi test case. First line contains a single number T indicates cases number. For each test case:
There is a singel number N indicates the aim number.
1
≤
T
≤
1000
1 \leq T \leq 1000
1≤T≤1000
1
≤
N
≤
10000
1 \leq N \leq 10000
1≤N≤10000
Output:
For each test case,ouput a number, indicates the length of the gun. If “JTH” can’t kill this number, output -1.
Sample Inuput | Sample Output |
---|---|
3 1 2 3 | 2 3 3 |
Hints:
None
Answer:
#include <iostream>
using namespace std;
int main(){
int a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0};
int T;
cin >> T;
while(1){
int N, x = 1;
cin >> N;
int s = 1;
for(int i = 0; i < 10;){
if(x % N != 0){
i += 1;
if (i == 10) i = 0;
s += 1;
if (s > 19){
cout << -1;
return 0;
}
x = x*10 + a[i];
}
else
break;
}
s += 1;
cout << "output:" << s;
}
return 0;
}