<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Sieve of Eratosthenes on Kelly Dev</title><link>https://kelly-chui.github.io/algorithmtags/sieve-of-eratosthenes/</link><description>Recent content in Sieve of Eratosthenes on Kelly Dev</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Tue, 28 Jul 2026 10:39:27 +0900</lastBuildDate><atom:link href="https://kelly-chui.github.io/algorithmtags/sieve-of-eratosthenes/index.xml" rel="self" type="application/rss+xml"/><item><title>Codeforces 230B. T-Primes</title><link>https://kelly-chui.github.io/ps/2026/ps-codeforces-230b-t-primes/</link><pubDate>Tue, 28 Jul 2026 10:39:27 +0900</pubDate><guid>https://kelly-chui.github.io/ps/2026/ps-codeforces-230b-t-primes/</guid><description>&lt;h2 id="문제"&gt;문제&lt;/h2&gt;
&lt;p&gt;&lt;a href="https://codeforces.com/problemset/problem/230/B"&gt;https://codeforces.com/problemset/problem/230/B&lt;/a&gt;&lt;/p&gt;
&lt;h2 id="풀이"&gt;풀이&lt;/h2&gt;
&lt;p&gt;T-Prime을 약수가 3개인 수라고 정의하고, $n$개의 크기의 수열 $x$의 원소 각각에 대해서 그 수가 T-Prime인지 확인하는 문제이다.&lt;/p&gt;
&lt;p&gt;약수가 3개라는 뜻은, $1$과 자기 자신 그리고 $\sqrt{x_i}$만을 약수로 가진다는 뜻이다. 즉, T-Prime은 어떤 수의 제곱이어야 한다.&lt;/p&gt;
&lt;p&gt;그 &amp;lsquo;어떤 수&amp;rsquo;의 조건은 무엇일까? 약수의 약수는 결국 약수이다. T-Prime은 $1$, &amp;lsquo;어떤 수&amp;rsquo;, 자기 자신만을 약수로 가지므로, &amp;lsquo;어떤 수&amp;rsquo;는 소수여야 한다. 결국 이 문제는 소수 판별 문제로 단순화된다.&lt;/p&gt;
&lt;p&gt;$x_i$의 최댓값이 $10^{12}$이지만, T-Prime 여부를 판별하려면 $\sqrt{x_i}$가 소수인지만 확인하면 되므로 체는 $\sqrt{10^{12}} = 10^6$까지만 구성하면 충분하다. 에라토스테네스의 체의 시간복잡도는 (거의) $O(N)$이고, 이후 각 쿼리는 $O(1)$에 처리되므로, $n \leq 10^5$인 입력 전체에 대해 전처리 $O(10^6)$ + 쿼리 $O(n)$으로 풀 수 있다.&lt;/p&gt;</description></item></channel></rss>