[PTA] 7-42 divisible singles (20 minutes)

Here, the term "bachelor" does not mean friends - Single Wang said that all of the numbers composed by one, such as 1,11,111,1111 and so on. Legend can be either a bachelor does not end with an odd number divisible by 5. For example, 111111 13 may be divisible. Now, your program to read an integer x, the integer is odd and certainly not at the end of 5. Then, after calculation, it outputs two numbers: the first number s, s is multiplied by x indicates a ruffian, the second number is the number of bits n of the ruffian. Such a solution is certainly not the only, subject of the request as you smallest output solution.

Tip: One obvious way is to gradually increase the number of bits bachelor until divisible by x so far. But the difficulty is that, s may be a very large number of - for example, the input program 31, and then outputs 15 3584229390681, 3584229390681 because the result is multiplied by 31 111111111111111, a total of 15 1.

Input format:
input given in line 5 to an end of the positive odd number x (<1000).

Output format:
output a corresponding minimum n and s in a row, separated by a space therebetween.

Sample input:
31

Sample output:
358,422,939,068,115

#include<stdio.h>

int main(){
    int x;
    scanf("%d",&x);
    int s=1; //用来表示光棍
    int c=1; //储存位数
    while(s<x){
        s=s*10+1; //光棍至少要比x大吧!
        c++;
    do{
        y=s%x; //储存余数
        printf("%d",s/x); 
        if(y==0){
            break;
        }
        s=y*10+1;
        c++;
    }while(y!=0); //自己手算一下111/15 就能理解了
    printf(" %d",c);
    return 0;
}
Published 48 original articles · won praise 0 · Views 300

Guess you like

Origin blog.csdn.net/weixin_46399138/article/details/105423614