forked from wandering007/ProjectEuler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP26.cpp
More file actions
51 lines (51 loc) · 1.09 KB
/
Copy pathP26.cpp
File metadata and controls
51 lines (51 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include<iostream>
#include<fstream>
#include<string>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<algorithm>
#include<math.h>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#define MAXN 1000000
#define LL long long
#define eps 1e-6
#define inf 0x3f3f3f3f
using namespace std;
int Hash[1005];
int RecurCycleLen(int divisor)
{
memset(Hash,0,sizeof(Hash));
int len=1, dividend = 1, rem = 1;
while(Hash[rem]==0&&rem!=0)//Hash值不为零,表明一个cycle的结束;rem=0,说明能除尽,不满足题意
{
Hash[rem] = len;
dividend = rem*10;
rem = dividend % divisor;
len++;
}
if(rem==0) return 0;
return len-Hash[rem];
}
int main()
{
int Max=0, rec = 1,temp;
for(int d=2;d<1000;d++)
{
temp = RecurCycleLen(d);
if(temp>Max)
{
Max = temp;
rec = d;
}
}
printf("1/%d contains the longest recurring cycle in its decimal fraction part.\n",rec);
return 0;
}