1 / 3

10110: Light, more light

10110: Light, more light. ★☆☆☆☆ 題組: Problem Set Archive with Online Judge 題號: 1 0110: Light, more light 解題者: 陳泓宇 解題日期: 200 9 年 5 月 15 日 題意: 輸入 n 代表走廊上有 n 個燈泡,依序編號為 1 到 n ,而管理員走 n 趟來開關燈泡,每當走第 i 趟時則切換編號能被 i 整除的燈泡,初始所有燈泡為關,求 n 趟結束後,第 n 個燈泡為開或關。 n ≤ 2^32-1. 題意範例: Sample input 3 6241

Télécharger la présentation

10110: Light, more light

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 10110: Light, more light • ★☆☆☆☆ • 題組:Problem Set Archive with Online Judge • 題號:10110:Light, more light • 解題者:陳泓宇 • 解題日期:2009年5月15日 • 題意: 輸入n代表走廊上有n個燈泡,依序編號為1到n,而管理員走n趟來開關燈泡,每當走第i趟時則切換編號能被i整除的燈泡,初始所有燈泡為關,求n趟結束後,第n個燈泡為開或關。 n ≤ 2^32-1

  2. 題意範例:Sample input3 6241 8191 0 Output for Sample Inputno yes no Example:

  3. 解法:解法一: • 如果i是n的因數,則切換燈泡, • So, continue (i = 1 to n) : i++ • =>TLE (Time Limit Exceed) 解法二: • (1) 使用unsigned long或long long,格式為%I64d。 • (2) 考慮n有幾個因數,若為奇數個則燈泡為開。 • (3) A number have Odd number of factors if and only if it is a Perfect Square • (4)So, if (sqrt (n) = Integer) then output: Yes otherwise No.

More Related