PS 부수기
Project Euler #26 Reciprocal cycles 본문
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
|
int solve(int n) {
set<int> p;
p.insert(1);
int num = 1;
int numnum = -1;
int cnt = 0;
bool startCycle = false;
while (1) {
num *= 10;
if (num % n == 0) return 0;
if (num % n == numnum) return cnt;
if (p.count(num % n) && startCycle == false) {
startCycle = true;
numnum = num % n;
}
num = num % n;
if (startCycle) cnt++;
p.insert(num % n);
}
}
int main() {
IOS;
int ans = -1, ansIndex;
for (int i = 2; i <= 1000; i++) {
if (solve(i) > ans) {
ansIndex = i;
ans = solve(i);
}
}
cout << ansIndex;
}
|
cs |
여기부턴 외국사이트에서 풀것이다!
나머지가 2번 나타났을 때부터 세기 시작해서 3번째 나타날때까지 cnt를 셌다. 너무 야매인가..
'Project Euler' 카테고리의 다른 글
Project Euler #28 : Number spiral diagonals (0) | 2020.08.08 |
---|---|
Project Euler #27 : Quadratic primes (0) | 2020.08.08 |
Project Euler #25 : 피보나치 수열에서 처음으로 1000자리가 되는 항은 몇 번째? (0) | 2020.08.07 |
Project Euler #24 : 0, 1, 2, 3, 4, 5, 6, 7, 8, 9로 만들 수 있는 1,000,000번째 사전식 순열은? (0) | 2020.08.07 |
Project Euler #23 : 두 초과수의 합으로 나타낼 수 없는 모든 양의 정수의 합은? (0) | 2020.08.07 |
Comments