LoginSignup
2
0

More than 1 year has passed since last update.

yukicoder contest 297 参戦記

Posted at

yukicoder contest 297 参戦記

A 1517 Party Location

重心に集合すれば良いのかと思ってたけど、どっちかの町だったのか……. WAになってしまったので、「つねに整数」を頼りに全探索になってしまった…….

d = int(input())
a, b = map(int, input().split())

result = 10 ** 15
for i in range(d + 1):
    result = min(result, i * a + (d - i) * b)
print(result)

B 1518 Simple Combinatorics

完全に数学. ある整数が出る確率は、1から出ない確率を引いたものなので 1-((N - 1)/N)K. これがN種類あり、求める答えはNKをかけたものなので、NK+1 - N(N-1)K (≡ 109 + 7) となる.

m = 1000000007

N, K = map(int, input().split())

print((pow(N, K + 1, m) - N * pow(N - 1, K, m)) % m)
2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0