Start brushing questions, I feel that the amount of code and the foundation are too scum, resulting in the data structure will not, slowly brush it ~
1. Title
Sample input:
31
Sample output:
3584229390681 15
2. Code
#include<stdio.h>
int main(){
int x;
scanf("%d",&x);
int cnt=0;
int a=0,c=0,d;
while(a<x){
a=a*10+1;
cnt++;
}
while(1){
printf("%d",a/x);
a%=x;
if(a==0) break;
a=a*10+1;
cnt++;
}
printf(" %d",cnt);
return 0;
}
3 Discussion
This topic is very interesting, ha, would have thought that a "simple" question, with the continuous circulation by 10 plus 1, and sure enough there are two test
timed out, then there would be no ,,, then the.
#include<stdio.h>
#include<math.h>
int main(){
int x;
scanf("%d",&x);
int i;
int cnt=0;
long long int a=0,c=0,d;
while(1){
a=a*10+1;
cnt++;
c=a/x;
d=a%x;
if(d==0){
printf("%lld %d",c,cnt);
break;
}
}
// printf("%lld %d",c,cnt);
return 0;
}
When I searched the Internet, I discovered a kinky trick, which is to simulate the operation of division, that is:
What does it mean?
That is, only a part of the bachelor number is generated first, 111 in the example, and then the division is performed, which is equivalent to calculating the result from the highest bit (the handwritten division operation step). When the remainder is not 0, add 1 at the end of the remainder (not Addition of addition, but the meaning of patchwork, that is, 1 "addition" 1 is 11).
Wonderful! ! !