結果

問題 No.746 7の倍数
ユーザー くれちー
提出日時 2018-11-04 19:32:56
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 9 ms / 2,000 ms
コード長 411 bytes
コンパイル時間 1,064 ms
コンパイル使用メモリ 80,960 KB
最終ジャッジ日時 2025-01-06 15:34:58
ジャッジサーバーID
(参考情報)
judge2 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:18:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   18 |   scanf("%zu", &n);
      |   ~~~~~^~~~~~~~~~~
main.cpp:19:8: warning: ignoring return value of ‘ssize_t write(int, const void*, size_t)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   19 |   write(STDOUT_FILENO, buf.data(), n == 0 ? 1 : n + 2);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <array>
#include <cstdio>
#include <unistd.h>

constexpr auto max_n = 100000;

constexpr auto create_buf() {
  std::array<char, 2 + max_n> buf { "0." };
  for (std::size_t i = 2; i < 2 + max_n; ++i) {
    buf[i] = "142857"[(i - 2) % 6];
  }
  return buf;
}

int main() {
  constexpr auto buf = create_buf();
  std::size_t n;
  scanf("%zu", &n);
  write(STDOUT_FILENO, buf.data(), n == 0 ? 1 : n + 2);
}
0