Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

36-H0ngJu #260

Merged
merged 2 commits into from
Dec 31, 2024
Merged

36-H0ngJu #260

merged 2 commits into from
Dec 31, 2024

Conversation

H0ngJu
Copy link
Collaborator

@H0ngJu H0ngJu commented Dec 2, 2024

๐Ÿ”— ๋ฌธ์ œ ๋งํฌ

๋จธ๋ฆฌ ํ†กํ†ก

โœ”๏ธ ์†Œ์š”๋œ ์‹œ๊ฐ„

1์‹œ๊ฐ„

โœจ ์ˆ˜๋„ ์ฝ”๋“œ

image



๋ฌธ์ œ ์ž์ฒด๋Š” ๊ต‰์žฅํžˆ ๊ฐ„๋‹จํ•ฉ๋‹ˆ๋‹ค.

์›์œผ๋กœ ์•‰์€ ํ•™์ƒ๋“ค์ด ํ•œ๋ช…์”ฉ ์ผ์–ด๋‚˜์„œ ์ž์‹ ์˜ ์ˆ˜๊ฐ€ ์•‰์•„์žˆ๋Š” ์‚ฌ๋žŒ์˜ ๋ฐฐ์ˆ˜ ์ด๋ฉด ๋จธ๋ฆฌ๋ฅผ ํ†กํ†ก์น˜๊ณ , ์ด ๋จธ๋ฆฌ๋ฅผ ๋•Œ๋ฆฐ ํ•™์ƒ์˜ ์ˆ˜๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.

๋ฌธ์ œ๋Š” N(1โ‰คNโ‰ค100,000)๋ช… ์ด๊ณ , ํ•™์ƒ์˜ ๋จธ๋ฆฌ์— ์“ด ์ˆ˜๋Š” 1โ‰คstudentโ‰ค1,000,000 ๋ผ๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.

์™„ํƒ์œผ๋กœ ๋Œ๋ฆฌ๋ฉด ์‹œ๊ฐ„์ดˆ๊ณผ๊ฐ€ ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค..



๊ทธ๋Ÿฌ๋ฉด ์–ด๋–ป๊ฒŒ ์ ‘๊ทผํ•  ๊ฒƒ์ธ๊ฐ€...

์ƒ๊ฐ์„ ํ•ด๋ดค๋Š”๋ฐ์š”

  1. n*m์€ n์˜ ๋ฐฐ์ˆ˜์ž„๊ณผ m์˜ ๋ฐฐ์ˆ˜์ž„์„ ์ด์šฉํ•œ๋‹ค.
  2. ๋•Œ๋ฆฐ ์ •๋ณด๋ฅผ ์ €์žฅํ•ด๋‘์—ˆ๋‹ค๊ฐ€ 1.์„ ์ด์šฉํ•˜์—ฌ ๋”ํ•ด์ค€๋‹ค.

์ด๋ ‡๊ฒŒ ์กฐํ•ฉํ•ด์„œ ์—ฌ๋Ÿฌ ์‹œ๋„๋ฅผ ํ•˜๋‹ค๋ณด๋‹ˆ,

์•ฝ์ˆ˜๋ฅผ ๊ตฌํ•ด์„œ ํ•ด๋‹น ์•ฝ์ˆ˜๋ฅผ ์ ์€ ํ•™์ƒ์˜ ์ˆ˜๋งŒํผ ๋•Œ๋ฆฌ๋„๋ก ๊ตฌํ˜„ํ•˜์˜€์–ด์š”.

N = int(input())
students = [int(input()) for _ in range(N)]
hits = [0 for _ in range(1000001)] # ์ˆซ์ž์˜ ๊ฐœ์ˆ˜
results = [0 for _ in range(N)]

for student in students: # ์ˆซ์ž k๋ฅผ ์ ์€ ํ•™์ƒ์˜ ์ˆ˜๋ฅผ ๊ธฐ๋ก
    hits[student] += 1

for idx in range(len(students)):
    for i in range(1, int(students[idx]**(1/2)) + 1):
        if students[idx] % i == 0:
            results[idx] += hits[i] # ํ•™์ƒ ์ˆ˜ ๋งŒํผ ๋•Œ๋ฆฌ๊ธฐ
            if (i ** 2) != students[idx]: # ์ œ๊ณฑ์ด ์•„๋‹Œ ๊ฒฝ์šฐ
                results[idx] +=  hits[students[idx] // i]

print(hits)
for r in results:
    print(r-1, end=" ")


์ฃผ์˜ํ•ด์•ผ ํ•  ๋ถ€๋ถ„!!

ํ•™์ƒ์ด ๋จธ๋ฆฌ์œ„์— ์“ด ์ˆ˜๋Š” ์ค‘๋ณต๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
๊ทธ๋ฆฌ๊ณ  ์ž์‹  ๋นผ๊ณ  ๋•Œ๋ฆฐ๋‹ค๋Š” ์ ์„ ์ฃผ์˜ํ•ด์•ผํ•ด์š”


students = [2, 2, 3, 1]
์ด๋ผ๊ณ  ๋˜์–ด ์žˆ์œผ๋ฉด students[0]์€ students[1]๊ณผ students[3]์„ ๋•Œ๋ฆด ์ˆ˜ ์žˆ์œผ๋ฏ€๋กœ 2๋ฒˆ ๋•Œ๋ฆด ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ž์‹  ๋นผ๊ณ  ๋•Œ๋ฆฐ๋‹ค -> ์ผ๋‹จ ๋‹ค ๋•Œ๋ฆฐ ํšŸ์ˆ˜๋ฅผ ๊ตฌํ•˜๊ณ  ์ž๊ธฐ ์ž์‹ (1)์„ ๋บ€๋‹ค

๋Š” ๋กœ์ง์œผ๋กœ ๊ตฌํ˜„ํ•˜๋Š” ๊ฒƒ์ด ๋” ์‰ฌ์šด ๊ฒƒ ๊ฐ™์•„์š”.


์•ฝ์ˆ˜ ๊ตฌํ•˜๋Š” ๊ณผ์ •์—์„œ students ์•ˆ์— ์ž์‹ ๊ณผ ๊ฐ™์€ ์‚ฌ๋žŒ์ด ์žˆ๋Š”์ง€
๋”๋ธ”์ฒดํฌ ํ•˜๋Š” ์ˆœ๊ฐ„ ๋˜ ์‹œ๊ฐ„์ดˆ๊ณผ๊ฐ€ ๋ฐœ์ƒํ•˜๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค...

๋‹ค ํ’€๊ณ  ๋‚˜๋‹ˆ๊นŒ ์ฝ”๋“œ๋Š” ๊ฐ„๋‹จํ•œ๋ฐ
์‹œ๊ฐ„์ดˆ๊ณผ๋ฅผ ํƒˆ์ถœํ•˜๋Š๋ผ ํž˜๋“ค์—ˆ์Šต๋‹ˆ๋‹ค...

๐Ÿ“š ์ƒˆ๋กญ๊ฒŒ ์•Œ๊ฒŒ๋œ ๋‚ด์šฉ

Copy link
Member

@tgyuuAn tgyuuAn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import kotlin.math.*;

fun main() {
    val N = readln().toInt()
    val answer = HashMap<Int, Int>()
    val counter = HashMap<Int, Int>()
    val numbers = mutableListOf<Int>()
    val forCheck = mutableSetOf<Int>()
    
    repeat(N) { idx ->
        val now = readln().toInt()
        counter[now] = (counter[now] ?: 0) + 1
        numbers.add(now)
        forCheck.add(now)
    }
    
    for(number in numbers) {
        if(answer[number] == null) {
            for(i in 1 until (sqrt(number.toFloat()).toInt()+1)) {
                if(number%i==0) {
                    answer[number] = (answer[number]?:0) + (counter[i] ?: 0)
                
                    if(i != number/i){
                        answer[number] = (answer[number]?:0) + (counter[number/i] ?: 0)
                    }
                }
            }
        }
        
        println((answer[number]?:1)-1)
    }
}

์™€ ์š”์ฆ˜ ์ฝ”ํ‹€๋ฆฐ์œผ๋กœ๋งŒ ํ’€๋ ค๊ณ  ํ•˜๋Š”๋ฐ,

ํ’€์ด๋Š” ๋– ์˜ค๋ฅด๋Š”๋ฐ ๊ตฌํ˜„ํ•˜๋Š”๋ฐ ์‹œ๊ฐ„์ด ๋„ˆ๋ฌด ์˜ค๋ž˜๊ฑธ๋ฆฌ๋„ค์š”,.,,,

๋ถ€์œ€,,,

์ด ๋ฌธ์ œ ์ƒ๊ฐ๋ณด๋‹ค ์‹œ๊ฐ„ ๋งŽ์ด๊ฑธ๋ ธ์Šต๋‹ˆ๋‹ค...

๋ฆฌ๋งˆ์ธ๋“œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹น ใ…Žใ…Žใ…Žใ…Žใ…Ž




++

์ž์‹  ๋นผ๊ณ  ๋•Œ๋ฆฐ๋‹ค -> ์ผ๋‹จ ๋‹ค ๋•Œ๋ฆฐ ํšŸ์ˆ˜๋ฅผ ๊ตฌํ•˜๊ณ  ์ž๊ธฐ ์ž์‹ (1)์„ ๋บ€๋‹ค

์ €๋Š” ์จ์ฃผ์‹  ๊ฒƒ ์ฒ˜๋Ÿผ ์ด๋ ‡๊ฒŒ ๊ตฌํ–ˆ์Šต๋‹ˆ๋‹ค!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants