Created
May 15, 2014 09:05
-
-
Save lotabout/c66258ab1c0b9d5deec9 to your computer and use it in GitHub Desktop.
Modified version of Molly's pro26.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#include<sys/types.h> | |
#include<memory.h> | |
int findmax(int a[]) | |
{ | |
int i; | |
for(i=1; i<1000; i++) | |
{ | |
if(a[i]>a[0]) | |
a[0] = a[i]; | |
} | |
return a[0]; | |
} | |
int find_index(int yu,int yushu[]) | |
{ | |
int i = 0; | |
int pos = -1; | |
for(i=0; i<999; i++) | |
{ | |
if(yu == yushu[i]) | |
{ | |
pos = i; | |
break; | |
} | |
} | |
return pos; | |
} | |
void add(int yu,int yushu[]) | |
{ | |
int i; | |
for(i=0; i<999; i++) | |
{ | |
if(yushu[i] == 0) | |
{ | |
yushu[i] = yu; | |
break; | |
} | |
} | |
} | |
int div(int a, int d, int yushu[]) | |
{ | |
int yu = a % d; | |
int pos = find_index(yu, yushu); | |
add(yu, yushu); | |
if (pos != -1) | |
{ | |
return 1; | |
} | |
else | |
{ | |
return 1 + div(yu*10, d, yushu); | |
} | |
} | |
int num_of_cycles(int d, int yushu[]) | |
{ | |
int pos; | |
int ret; | |
memset(yushu,0,sizeof(int)*1000); | |
if(d<10){ | |
pos = div(10, d, yushu) - 1; | |
ret = pos - find_index(yushu[pos], yushu); | |
} | |
else if(d<100){ | |
pos = div(100, d, yushu) - 1; | |
ret = pos - find_index(yushu[pos],yushu); | |
} | |
else if(d<1000){ | |
pos = div(1000, d, yushu) - 1; | |
ret = pos - find_index(yushu[pos], yushu); | |
} | |
return ret; | |
} | |
int main() | |
{ | |
int pos; | |
int rec; | |
int i,d; | |
int num[1000]; | |
int yushu[1000]; | |
memset(yushu,0,sizeof(int)*1000); | |
memset(num,0,sizeof(int)*1000); | |
for(d=2;d<1000;d++) | |
{ | |
int tmp = d; | |
while (tmp%2 == 0) //将num中的因子2全部去除 | |
tmp /=2; | |
while (tmp % 5 == 0) //将num中的因子5全部去除 | |
tmp /= 5; | |
if(tmp==1||tmp==0) | |
continue; | |
num[d] = num_of_cycles(d, yushu); | |
} | |
//max length | |
rec = findmax(num); | |
for(i=1;i<1000;i++) | |
{ | |
if(num[i]==rec) | |
{ | |
d=i; | |
break; | |
} | |
} | |
printf("The result is %d\n",d); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment