◦ N ͕ͲͷͰׂΔ͜ͱ͕Ͱ͖Δ͔ 1 ͔Β N ·ͰͷͰࢼ͢ ਖ਼͍͑͠ग़ྗ͞ΕΔ͕ɺ ڝϓϩͰϓϩάϥϜͷ࣮ߦ࣌ؒʹ੍ݶ͕͋Δʢ2ඵҎͳͲʣͨΊ͜ΕͰNG • ίϯϐϡʔλ 1 ඵʹ 10^8 ճܭࢉͰ͖Δ • ࠓճͷͰ N ͕࠷େ 10^12 ͷ߹ 10000ඵʢ3࣌ؒऑʣ͔͔ͬͯ͠·͏ • ͰͲ͏͢Δ͔ʁͬͱޮྑ͘ܭࢉͰ͖ͳ͍͔ߟ͑ͯΈΔ 7 for i in 1ʙN if ( N % i == 0 ) print( i )ɹ← i ͰׂΓΕͨΒ i N ͷ
A. N ͕ͲͷͰׂΔ͜ͱ͕Ͱ͖Δ͔ 1 ͔Β √N ·ͰͷͰࢼ͢ for i in 1ʙ√Nɹ← N / i Ұॹʹग़ྗ͢Δ͜ͱͰ √N ·ͰͰͯ͢ͷ͕ἧ͏ if ( N % i == 0 ) print( i )ɹ← i ͰׂΓΕͨΒ i N ͷ if ( N / i != i ) print( N / i )ɹ← i ͰׂΓΕͨΒ N / i N ͷ • N ͕࠷େ 10^12 ͷ߹Ͱϧʔϓճ 10^6 • ίϯϐϡʔλ͕ 1 ඵʹ 10^8 ճܭࢉ͢Δͱͯ͠ 1ඵҎʹܭࢉ͕ऴΘΔ ྫ͑ɺ100ͷΛٻΊΔͱ͖ 100͕5ͰׂΓΕΔͳΒ10020(=100/5)ͰׂΓΕΔ 8
10^6 ҎԼ ◦ ֤Ϣʔβʹ͍ͭͯͦΕΑΓ ID ͕খ͍͞ϢʔβΛͯ֬͢ೝ for i in 1ʙNɹ← ࠓͷରϢʔβ for j in 1ʙ(i - 1)ɹ← ରϢʔβΑΓID͕খ͍͞Ϣʔβ if ( username[ i ] == username[ j ] ) flag = 1ɹ← Ϣʔβ໊͕ඃ͍ͬͯͨΒνΣοΫ if (flag == 1) print( i ) 10 ID رϢʔβ໊ 1 aaa 2 bbb 3 aaa 4 aaa 5 ccc 6 ccc