結果

問題 No.589 Counting Even
ユーザー dptbldptbl
提出日時 2017-11-03 23:31:34
言語 D
(dmd 2.109.1)
結果
WA  
実行時間 -
コード長 809 bytes
コンパイル時間 669 ms
コンパイル使用メモリ 106,024 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-12 22:18:55
合計ジャッジ時間 1,349 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 6 WA * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

import core.bitop;
import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.format;
import std.math;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

long g(long n, long r)
{
  long v = 1;
  foreach (i; 0..n) {
    v *= i + 1;
  }
  foreach (i; 0..r) {
    v /= i + 1;
  }
  foreach (i; 0..(n - r)) {
    v /= i + 1;
  }
  return v;
}

long f(long n)
{
  long cnt = 0;
  foreach (i; 1..n) {
    long v = g(n, i);
    if (v % 2 == 0) {
      ++cnt;
    }
  }
  return cnt;
}

void main()
{
  long n = readln.chomp.to!long;
  if (n < 1000) {
    n.f.writeln;
    return;
  }
  long two = 2;
  long cnt = 0;
  while (two <= n) {
    cnt += n / two;
    two <<= 1L;
  }
  --cnt;
  cnt += n.popcnt;
  cnt.writeln;
}
0