| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
高精度超时的,要*10+1普通除法计算/*输入满足要求的 n ,然后 n 的某倍数是一个完全由1组成的数,要求输出这个完全由1组成的数有几位数*/
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
#include<string.h>
char a[1000000],c[1000000];
int dividor(char* a,int b,char* c)
{
int i,j,temp=0,n;
char* s;
n=strlen(a);
s=(char*)malloc(sizeof(char)*(n+1));
for (i=0;a[i]!=0;i++)
{
temp=temp*10+a[i]-'0';
s[i]=temp/b+'0';
temp%=b;
}
s[i]='\0';
for (i=0;s[i]=='0'&&s[i]!='\0';i++);
if (s[i]=='\0')
{
c[0]='0';
c[1]='\0';
}
else
{
for (j=0;s[i]!='\0';i++,j++)
c[j]=s[i];
c[j]='\0';
}
free(s);
return temp;
}
int main()
{
int n,i;
while(scanf("%d",&n))
{
if(n==0) {printf("0\n"); continue;}
a[0]='1';a[1]='\0';
for(i=0;;i++)
{
if(dividor(a,n,c)==0)
{
printf("%d\n",strlen(a));
break;
}
else
{
a[i+1]='1';a[i+2]='\0';
}
}
}
//system("pause");
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator