baekjoon 20260311-12
This commit is contained in:
parent
04c483ae12
commit
dee2ba0a7d
1
code_study/Baekjoon/python/15439.py
Normal file
1
code_study/Baekjoon/python/15439.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
print((lambda x: x*(x-1))(int(input())))
|
||||||
33
code_study/Baekjoon/swift/9527.swift
Normal file
33
code_study/Baekjoon/swift/9527.swift
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
var dp: [Int64] = Array(repeating: 0, count: 55)
|
||||||
|
|
||||||
|
for n in 1...54 {
|
||||||
|
dp[n] = 2*dp[n-1] + (1 << (n-1))
|
||||||
|
}
|
||||||
|
|
||||||
|
func countOne(_ N: Int64) -> Int64 {
|
||||||
|
var res: Int64 = 0
|
||||||
|
var n: Int64 = N
|
||||||
|
|
||||||
|
for i in stride(from: 54, to: 0, by: -1) {
|
||||||
|
let LSB: Int64 = (1 << (i-1)) & n
|
||||||
|
|
||||||
|
if LSB != 0{
|
||||||
|
res += dp[i-1]
|
||||||
|
res += n - (1 << (i-1)) + 1
|
||||||
|
}
|
||||||
|
|
||||||
|
n &= ((1 << (i-1)) - 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
guard let input = readLine() else { return }
|
||||||
|
let nums: [Int64] = input.split(separator: " ").compactMap{Int64($0)}
|
||||||
|
|
||||||
|
let ans: Int64 = countOne(nums[1]) - countOne(nums[0]-1)
|
||||||
|
print(ans)
|
||||||
|
}
|
||||||
|
|
||||||
|
main()
|
||||||
Loading…
x
Reference in New Issue
Block a user