結果

問題 No.746 7の倍数
ユーザー ikdikd
提出日時 2018-10-19 22:48:57
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 1,299 bytes
コンパイル時間 587 ms
コンパイル使用メモリ 84,144 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-03 21:14:06
合計ジャッジ時間 2,245 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 5 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 4 ms
4,376 KB
testcase_12 AC 5 ms
4,376 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 4 ms
4,380 KB
testcase_15 AC 4 ms
4,380 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 4 ms
4,380 KB
testcase_18 AC 3 ms
4,376 KB
testcase_19 AC 4 ms
4,380 KB
testcase_20 AC 3 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 5 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

void main() {
  import std.stdio, std.string, std.conv, std.algorithm;

  int p;
  rd(p);
  /*
  char[] n;
  n ~= "1";
  foreach (_; 0 .. p)
    n ~= "0";
  auto memo = new int[][][](n.length + 1, 2, 7);
  afill(memo, -1);
  int f(size_t i, bool less, int sum) {
    if (i == n.length) {
      return sum % 7 == 0;
    } else {
      if (memo[i][less][sum] >= 0) {
        return memo[i][less][sum];
      }
      auto digit = less ? 9 : n[i] - '0';
      int ret = 0;
      for (int d = 0; d <= digit; d++) {
        auto l = less || d < digit;
        auto s = (sum * 10 + d) % 7;
        ret += f(i + 1, l, s);
      }
      return memo[i][less][sum] = ret;
    }
  }

  writeln(f(0, 0, 0) - 1);
  */

  if (p == 0) {
    writeln(0);
    return;
  }
  auto s = "142857";
  char[] ans;
  ans ~= "0.";
  foreach (i; 0 .. p) {
    ans ~= s[i % s.length];
  }
  writeln(ans);
}

void afill(Range, Type)(Range r, Type value) {
  static if (is(typeof(r) == Type[])) {
    foreach (ref elem; r)
      elem = value;
  } else {
    foreach (ref arr; r)
      afill(arr, value);
  }
}

void rd(T...)(ref T x) {
  import std.stdio : readln;
  import std.string : split;
  import std.conv : to;

  auto l = readln.split;
  assert(l.length == x.length);
  foreach (i, ref e; x)
    e = l[i].to!(typeof(e));
}
0