※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※
이번에 볼 문제는 백준 11290번 문제인 Wonowon이다.
문제는 아래 링크를 확인하자.
https://www.acmicpc.net/problem/11290
11290번: Wonowon
There is a little village in northern Canada called Wonowon, its name coming from the fact that it is located at Mile 101 of the Alaska Highway. While passing through this village, a wandering mathematician had an idea for a new type of number, which he ca
www.acmicpc.net
이를 이용해 (2, 3 및 5를 제외한)
각 수가 소수인지는 에라토스테네스의 체를 이용해 미리 전처리해두는 것으로 판별할 수 있다. 이 문제에서는 입력의 크기가 충분히 작으므로
아래는 제출한 소스코드이다.
#include <iostream>
using namespace std;
int ans;
int cur = 1, cnt = 1;
bool sieve[10001];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
for (int i = 2; i < 100; i++) {
if (sieve[i]) continue;
for (int j = i * i; j < 10001; j += i) sieve[j] = 1;
}
int N; cin >> N;
for (int p = 7; p <= N; p++) {
if (sieve[p]) continue;
cur = 1, cnt = 1;
while (cur) cur = (cur * 100 + 1) % p, cnt += 2;
if (cnt == p - 2) ans++;
}
cout << ans;
}
'BOJ' 카테고리의 다른 글
[BOJ 24087 // C++] アイスクリーム (Ice Cream) (0) | 2022.12.14 |
---|---|
[BOJ 26314 // C++] Vowel Count (0) | 2022.12.13 |
[BOJ 11287 // C++] Margaret’s Minute Minute Manipulation (0) | 2022.12.13 |
[BOJ 11288 // C++] Ether's Encryption (0) | 2022.12.13 |
[BOJ 26307 // C++] Correct (0) | 2022.12.13 |