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;
}
本文来自博客园,作者:LZaRD,转载请注明原文链接:https://www.cnblogs.com/lzard/p/14682670.html

浙公网安备 33010602011771号