結果

問題 No.1256 連続整数列
ユーザー tkmst201tkmst201
提出日時 2021-01-10 10:52:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,445 bytes
コンパイル時間 2,056 ms
コンパイル使用メモリ 196,348 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-13 02:22:46
合計ジャッジ時間 3,826 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = false;
//---------------------------------//

/*
長さ L (>= 3) の連続整数列の合計は (L-1)L/2 (mod. L) の形すべて取れる。
L が奇数の場合、L-1 は偶数なので、(L-1)L/2 = (L-1)/2 * L \equiv 0 (mod. L) となる。
つまり、A に奇素因数が含まれていれば "YES"
それ以外の場合、すなわち A = 2^m (m >= 0) と表されている場合を考える。

なんとなく L = 2^l (l >= 2) としてみる。
(L-1)L/2 = (2^l - 1) 2^{l-1}, \mod 2^l で A と等しければ ok
(2^l - 1) 2^{l-1} \nequiv 0 \mod 2^l であることに注意すると、
m >= l のとき、A \equiv 0 \mod 2^l であるので作れない。
よって、m < l \Leftrightarrow m + 1 <= l \Leftrightarrow m <= l - 1 のみ考えれば良い。

2^m で割ると、(2^l - 1) 2^{l-1-m} \equiv 1 \mod 2^{l-m} であれば良い。
l - m = 1 のとき、(2^l - 1) 2^{l-1-m} が奇数であれば満たすが、(2^l - 1) が奇数なので ok
l = 1 + m としたい。l >= 2 の制約より、m >= 1 のときは "YES"

最後に、m = 0 \Leftrightarrow A = 1 のときを考える。
この場合を考えていたら上に書いた考察は不要なことに気づいた。一旦リセット。
A に奇素因数が含まれていないときは A = 2^m (m >= 0) と表されるが L = 奇数とした場合、A \nequiv 0 \mod L なので無理
(要素の和 \equiv 0 \mod L となるのだった)

つまり、L が偶数, L = 2x (x >= 2) と表されているときを考えれば良い。
このとき総和は (L-1)L/2 = (2x-1)x = 2x^2 - x
\mod 2x で A と一致すれば良いのだが、
2^x^2 - x \equiv x \mod 2x であるので、2x = 2A とすれば一致する。
x >= 2 なので、A >= 2 なら "YES"
A = 1 のとき "NO"

まとめると N=1 のときかつそのときに限り "NO"
*/

int main() {
	int A;
	cin >> A;
	puts(A == 1 ? "NO" : "YES");
}
0