#include<stdio.h>
int main ()
{ int s,min,x,n;
double i ;
scanf("%d",&x);
for (i=1,n=0;;i=i*10+1)
{ n++;
if( (int)i%x==0)
{
printf("%d %d",i/x,n);
break ;
}
}
}
问问为什么我这样的代码最后会出现运行超时啊
}
}
问问为什么我这样的代码最后会出现运行超时啊
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int main() { //模拟手动算除法过程
int x;
scanf("%d", &x);
int count = 1;
int a = 1; //a用来表示光棍数
//通过循环求出能除以x的最小a值(注:此处并不要求整除,能进行除法运算即可,即a>=x便可)
while (a < x) {
a = a * 10 + 1;
count++;
}
printf("%d", a / x); //输出最高位数字
int t = a % x; //用t记录余数;
while (t!=0) { //利用循环将商从高到低位依次输出,直到余数为0。
t = t * 10 + 1;
printf("%d", t / x);
count++;
t %= x;
}
printf(" %d", count);
return 0;
}