更新时间:2022-09-20 15:24:23
Find the value of d 1000 for which 1/d contains the longest recurring cycle in its decimal fraction part.
1.package euler;
2.
3.import java.util.HashSet;
4.import java.util.Set;
5.
6./**
7. *
8. * @author hongfa.yy
9. * @version 2013-2-6 下午4:48:51
10. */
11.public class Problem26 {
12. public static void main(String[] args) {
13. int max = 0;
14. int max_d=0;
15. for (int i = 1; i < 1000; i++) {
16. int count = count(i);
17. if (count > max){
18. max_d=i;
19. max = count;
20. }
21.
22. }
23. System.out.println(max_d);
24. }
25.
26. private final static int decimalism = 10;
27.
28. private static int count(int denominator) {
29. Set<Integer> set = new HashSet<>();
30. int mode = 1 * decimalism % denominator;
31. while (mode != 0) {
32. if (!set.contains(mode))
33. set.add(mode);
34. else
35. return set.size();
36. mode = mode * decimalism % denominator;
37. }
38.
39. return 0;
40. }
41.}