FOJ Playing with Calculator (模运算)

Problem Description

Pete is playing a game. He types on a calculator a natural number K and then presses the '+' key. The display still shows K. Pete wants to have on the display a number that is formed using only one figure. In order to get that he presses, if it is necessary, the '=' key several times (maybe 0). The result after the first pressing is K+K. After each pressing the number K is added to the sum. Find out whether Pete will achieve his goal or not, and what number, consisting all of identical figures, he will get first. Consider the capacity of the calculator to be unlimited.

K < 1000

 

Input

The input file contains the number K.

Process to the end of file.

 

Output

The output file must contain two numbers: first the figure that forms the result and then the number of digits of the result. If multiple solution exists, first minimize the figure then minimize the number of digits. If finding the desired result is impossible, the output file must contain only one number -1 (minus 1). The numbers in the output file must be separated by one space.

 

 

Sample Input

37

Sample Output

1 3

 

 

大致题意,给你一个数k,n*k==result, result由相同数字组成,输出数字和这个数字的个数。转化成就是result能被k整除,由于result是有相同数字组成的,所以求模可以递推进行计算。

 

AC代码:

 

 

# include <stdio.h> 
int main(){
	int i, j, k, a, b, flage, n;
	int f[10010];
	while(scanf("%d", &n)!=EOF){
		flage=0;
		for(i=1; i<=9; i++){
			f[0]=0;
			for(j=1; j<=n; j++){
				f[j]=(f[j-1]*10+i)%n;
				if(f[j]==0){
					printf("%d %d\n", i, j);
					flage=1;
					break;
				}
			}
			if(flage){
				break;
			}
		}
		if(!flage)
		printf("-1\n");
	}
	return 0;
}

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值