<?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>Prime on Yu-Cheng's Notes</title><link>https://linkingmon.github.io/blog/tags/prime/</link><description>Recent content in Prime on Yu-Cheng's Notes</description><generator>Hugo -- 0.166.0</generator><language>en-us</language><lastBuildDate>Sun, 04 Jan 2026 00:00:00 +0000</lastBuildDate><atom:link href="https://linkingmon.github.io/blog/tags/prime/index.xml" rel="self" type="application/rss+xml"/><item><title>LC 1390 - Four Divisors</title><link>https://linkingmon.github.io/blog/coding/lc-1390/</link><pubDate>Sun, 04 Jan 2026 00:00:00 +0000</pubDate><guid>https://linkingmon.github.io/blog/coding/lc-1390/</guid><description>&lt;h2 id="approach"&gt;Approach&lt;/h2&gt;
&lt;p&gt;Originally I thought that we just need to find the number that can be divided by two primes. &lt;code&gt;num = prime1 * prime2&lt;/code&gt;, but got an WA, since I&amp;rsquo;ve ignored the &lt;code&gt;num = prime1 * prime1 * prime1&lt;/code&gt;, such as 8 has 1, 2, 4, 8 as divisors.&lt;/p&gt;
&lt;p&gt;So the overall method is that we precalculate the prime and check the above conditions.&lt;/p&gt;
&lt;p&gt;My first submit is slow since I tried to build prime up to maxNum, but actually we can build to &lt;code&gt;floor(sqrt(maxNum))&lt;/code&gt;. I was thinking that when &lt;code&gt;prime1&lt;/code&gt; is smaller in this square-root range, but &lt;code&gt;prime2&lt;/code&gt; would not, so I build the entire prime inside the whole range. Actually, even when &lt;code&gt;prime2&lt;/code&gt; is larger then the square-root range, we can walk the prime again and check if there are other divisors (this can reduce lots of complexity!).&lt;/p&gt;</description></item><item><title>LC 2523 - Closest Prime Numbers in Range</title><link>https://linkingmon.github.io/blog/coding/lc-2523/</link><pubDate>Fri, 07 Mar 2025 00:00:00 +0000</pubDate><guid>https://linkingmon.github.io/blog/coding/lc-2523/</guid><description>&lt;p&gt;[translate by ChatGPT]
It’s been a while since I worked on prime-related problems. At first, I thought I needed to store previously computed primes, but it turns out that wasn’t necessary.&lt;/p&gt;
&lt;p&gt;This problem has many boundary conditions. When dealing with primes, I need to be especially careful about handling 1 and 2 correctly.&lt;/p&gt;
&lt;p&gt;Also, when checking whether a number is prime, it’s enough to check up to &lt;code&gt;sqrt(n)&lt;/code&gt;. That’s much faster than checking up to &lt;code&gt;n/2&lt;/code&gt;.&lt;/p&gt;</description></item></channel></rss>