FOJ Playing with Calculator (模运算)

来源:互联网 发布:判断矩阵计算公式 编辑:程序博客网 时间:2024/05/17 18:49

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
原创粉丝点击