7-42 整除光棍

[https://pintia.cn/problem-sets/1365920627062833152/problems/1365920667080687657](7-42 整除光棍)

分析:使用模拟除法,当取模的结果小于被除数时,不断乘10+1。s%x==0即表明找到了那个光棍数字

#include<stdio.h>
int main(void){
    int s, cnt ;
    s = cnt = 1;
    int x;
    scanf("%d", &x);
    
    while(s < x){
        cnt++;
        s = s * 10 + 1;
    }
    while( printf("%d", s / x), s % x != 0 ){
        s = s % x;
        if(s < x){
            s = s * 10 + 1;
            cnt++;
        }
    }
    printf(" %d\n",cnt);
    return 0;
}
posted @ 2021-04-20 20:17  LZaRD  阅读(105)  评论(0)    收藏  举报