From 3edb455dedcc968ff295dfd8f8c8db2a7e5c6cb6 Mon Sep 17 00:00:00 2001 From: beomsun0829 Date: Fri, 15 Jul 2022 20:34:07 +0900 Subject: [PATCH] =?UTF-8?q?[3=EC=A3=BC=EC=B0=A8]=20:=20=ED=99=8D=EB=B2=94?= =?UTF-8?q?=EC=88=9C=20-=204913=20=ED=8E=98=EB=A5=B4=EB=A7=88=EC=9D=98=20?= =?UTF-8?q?=ED=81=AC=EB=A6=AC=EC=8A=A4=EB=A7=88=EC=8A=A4=20=EC=A0=95?= =?UTF-8?q?=EB=A6=AC=20Gold4=20(#60)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main.go" | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 "\355\231\215\353\262\224\354\210\234/4913 - \355\216\230\353\245\264\353\247\210\354\235\230 \355\201\254\353\246\254\354\212\244\353\247\210\354\212\244 \354\240\225\353\246\254/main.go" diff --git "a/\355\231\215\353\262\224\354\210\234/4913 - \355\216\230\353\245\264\353\247\210\354\235\230 \355\201\254\353\246\254\354\212\244\353\247\210\354\212\244 \354\240\225\353\246\254/main.go" "b/\355\231\215\353\262\224\354\210\234/4913 - \355\216\230\353\245\264\353\247\210\354\235\230 \355\201\254\353\246\254\354\212\244\353\247\210\354\212\244 \354\240\225\353\246\254/main.go" new file mode 100644 index 0000000..87ce899 --- /dev/null +++ "b/\355\231\215\353\262\224\354\210\234/4913 - \355\216\230\353\245\264\353\247\210\354\235\230 \355\201\254\353\246\254\354\212\244\353\247\210\354\212\244 \354\240\225\353\246\254/main.go" @@ -0,0 +1,82 @@ +package main + +import ( + "fmt" +) + +var ARR_SIZE int = 1000010 +var prime [1000010]bool +var primesum [1000010]int +var squaresum [1000010]int + +func main() { + Init() + getPrimes() + //debugprint() + + for i := 3; i < ARR_SIZE; i++ { + if prime[i] == true { + primesum[i] = primesum[i-1] + 1 + } else { + primesum[i] = primesum[i-1] + } + + if prime[i] == true && (i%4) == 1 { + squaresum[i] = squaresum[i-1] + 1 + } else { + squaresum[i] = squaresum[i-1] + } + } + + for { + var L, U int + fmt.Scan(&L, &U) + + x, y := 0, 0 + + if L == -1 && U == -1 { + return + } + + if L >= 1 { + x = primesum[U] - primesum[L-1] + y = squaresum[U] - squaresum[L-1] + } else if L < 1 && U >= 0 { + x = primesum[U] + y = squaresum[U] + } else { + x = 0 + y = 0 + } + + fmt.Printf("%d %d %d %d\n", L, U, x, y) + } + +} + +func Init() { + for i := 2; i < ARR_SIZE; i++ { + prime[i] = true + primesum[i] = 0 + squaresum[i] = 0 + } + primesum[2] = 1 + squaresum[2] = 1 +} + +func getPrimes() { + prime[1] = false + for i := 2; i*i < ARR_SIZE; i++ { + if prime[i] == true { + for j := i * i; j < ARR_SIZE; j += i { + prime[j] = false + } + } + } +} + +func debugprint() { + for i := 0; i < 50; i++ { + fmt.Printf("%d %d \n", i, prime[i]) + } +}