天津大学2019ACM新生赛

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 1T1000
1 ≤ N ≤ 10000 1 \leq N \leq 10000 1N10000

Output:
For each test case,ouput a number, indicates the length of the gun. If “JTH” can’t kill this number, output -1.

Sample InuputSample 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;
}
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值