結果

問題 No.887 Collatz
ユーザー MarcusAureliusAntoninus
提出日時 2019-09-20 21:53:30
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 306 bytes
コンパイル時間 2,234 ms
コンパイル使用メモリ 191,416 KB
最終ジャッジ日時 2025-01-07 18:43:54
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:6:19: warning: format ‘%lld’ expects argument of type ‘long long int*’, but argument 2 has type ‘int64_t*’ {aka ‘long int*’} [-Wformat=]
    6 |         scanf("%lld", &n);
      |                ~~~^   ~~
      |                   |   |
      |                   |   int64_t* {aka long int*}
      |                   long long int*
      |                %ld
main.cpp:17:24: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 3 has type ‘int64_t’ {aka ‘long int’} [-Wformat=]
   17 |         printf("%d\n%lld\n", i1, n_max);
      |                     ~~~^         ~~~~~
      |                        |         |
      |                        |         int64_t {aka long int}
      |                        long long int
      |                     %ld
main.cpp:6:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    6 |         scanf("%lld", &n);
      |         ~~~~~^~~~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>

int main()
{
	int64_t n;
	scanf("%lld", &n);
	int i1{-1};
	int64_t n_max{n};
	for (int i{}; i <= 400; i++)
	{
		if (i1 < 0 && n == 1) i1 = i;
		if (n & 1) n = 3 * n + 1;
		else n /= 2;
		if (i1 < 0)
			n_max = std::max(n, n_max);
	}
	printf("%d\n%lld\n", i1, n_max);

	return 0;
}
0