結果
問題 | No.1260 たくさんの多項式 |
ユーザー | semisagi |
提出日時 | 2020-10-16 22:52:07 |
言語 | Swift (5.10.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,217 bytes |
コンパイル時間 | 11,826 ms |
コンパイル使用メモリ | 129,332 KB |
実行使用メモリ | 9,344 KB |
最終ジャッジ日時 | 2024-07-20 23:13:37 |
合計ジャッジ時間 | 39,518 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 22 ms
9,216 KB |
testcase_01 | AC | 23 ms
9,088 KB |
testcase_02 | AC | 23 ms
9,216 KB |
testcase_03 | AC | 22 ms
9,088 KB |
testcase_04 | AC | 22 ms
9,088 KB |
testcase_05 | AC | 23 ms
9,216 KB |
testcase_06 | AC | 22 ms
9,088 KB |
testcase_07 | AC | 23 ms
9,088 KB |
testcase_08 | AC | 22 ms
9,216 KB |
testcase_09 | AC | 22 ms
9,216 KB |
testcase_10 | AC | 23 ms
9,088 KB |
testcase_11 | AC | 22 ms
9,216 KB |
testcase_12 | AC | 22 ms
9,216 KB |
testcase_13 | AC | 22 ms
9,216 KB |
testcase_14 | AC | 23 ms
9,088 KB |
testcase_15 | AC | 22 ms
9,088 KB |
testcase_16 | AC | 22 ms
9,088 KB |
testcase_17 | AC | 23 ms
9,216 KB |
testcase_18 | AC | 22 ms
9,088 KB |
testcase_19 | AC | 22 ms
9,216 KB |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | WA | - |
testcase_44 | WA | - |
testcase_45 | WA | - |
testcase_46 | WA | - |
testcase_47 | WA | - |
testcase_48 | AC | 50 ms
9,216 KB |
testcase_49 | WA | - |
testcase_50 | WA | - |
testcase_51 | WA | - |
testcase_52 | WA | - |
testcase_53 | WA | - |
testcase_54 | WA | - |
testcase_55 | WA | - |
testcase_56 | WA | - |
testcase_57 | WA | - |
testcase_58 | WA | - |
testcase_59 | WA | - |
testcase_60 | WA | - |
ソースコード
struct Scanner { private var elements = [String]() private var index = 0 mutating func peek() -> String { while elements.count == index { elements = readLine()!.split(separator: " ").map(String.init) index = 0 } return elements[index] } mutating func next() -> String { let value = peek() index += 1 return value } mutating func nextInt() -> Int { return Int(next())! } mutating func nextDouble() -> Double { return Double(next())! } } let MOD = 1000000007 struct Zn: CustomStringConvertible { let n: Int init(_ n: Int) { self.n = n } var description: String { String(self.n) } static var zero = Zn(0) static var one = Zn(1) static func + (lhs: Self, rhs: Self) -> Self { let n = lhs.n + rhs.n return Zn(n < MOD ? n : n - MOD) } static func + (lhs: Self, rhs: Int) -> Self { return lhs + Zn(rhs) } static func + (lhs: Int, rhs: Self) -> Self { return Zn(lhs) + rhs } static func - (lhs: Self, rhs: Self) -> Self { let n = lhs.n - rhs.n return Zn(n >= 0 ? n : n + MOD) } static func - (lhs: Self, rhs: Int) -> Self { return lhs - Zn(rhs) } static func - (lhs: Int, rhs: Self) -> Self { return Zn(lhs) - rhs } static func * (lhs: Self, rhs: Self) -> Self { Zn((lhs.n * rhs.n) % MOD) } static func * (lhs: Self, rhs: Int) -> Self { return lhs * Zn(rhs) } static func * (lhs: Int, rhs: Self) -> Self { return Zn(lhs) * rhs } static func += (lhs: inout Self, rhs: Self) { lhs = lhs + rhs } static func += (lhs: inout Self, rhs: Int) { lhs = lhs + Zn(rhs) } static func -= (lhs: inout Self, rhs: Self) { lhs = lhs - rhs } static func -= (lhs: inout Self, rhs: Int) { lhs = lhs - Zn(rhs) } static func *= (lhs: inout Self, rhs: Self) { lhs = lhs * rhs } static func *= (lhs: inout Self, rhs: Int) { lhs = lhs * Zn(rhs) } func pow(_ n: Int) -> Self { if n == 0 { return Zn(1) } else if n % 2 == 1 { return self * self.pow(n - 1) } else { return (self * self).pow(n / 2) } } var inverse: Self { self.pow(MOD - 2) } } var scanner = Scanner() let N = scanner.nextInt() func f(n: Int, x: Int) -> Zn { var n = n var result = 0 while n > 0 { result += n % x n /= x } return Zn(result % MOD) } func sum1(l: Int, r: Int) -> Zn { Zn((r - l) % MOD) * Zn((l + r - 1) % MOD) * Zn(2).inverse } var answer = Zn.zero for i in 2 ... min(N, 1000000) { answer += f(n: N, x: i) } var k = 1000001 while k <= N { var l = k var r = N + 1 while r - l > 1 { let mid = (l + r) / 2 if N / k != N / mid { r = mid } else { l = mid } } answer += Zn(r - k) * (N % MOD) answer += Zn(r - k) * (N / k % MOD) answer -= sum1(l: k, r: r) * (N / k % MOD) k = r } print(answer)