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
Sample Input
Sample Output
大致题意,给你一个数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;
}