結果

問題 No.1198 お菓子配り-1
ユーザー startcppstartcpp
提出日時 2020-08-29 01:44:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 806 bytes
コンパイル時間 519 ms
コンパイル使用メモリ 65,384 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-28 01:35:08
合計ジャッジ時間 997 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

//(A + B)(A - B) = N -> よく分からん
//Bを固定してAを動かす気持ちと関連して、A = B + n (n > 0)とおきたい.
//2Bn + n^2 = N
//・2B + 1 = N, n = 1 ⇔ B % 2 == 1 and B >= 3
//・4B + 4 = N, n = 2 ⇔ B % 4 == 0 and B >= 8
//で、n >= 3についてはこの2つに帰着できて、これが存在条件.
#include <iostream>
#include <string>
using namespace std;

int main() {
	string s;
	cin >> s;
	
	if (s.length() == 1) {
		if (s[0] == '3' || s[0] == '5' || s[0] == '7' || s[0] == '8' || s[0] == '9') {
			cout << 1 << endl;
		}
		else {
			cout << -1 << endl;
		}
	}
	else {
		int mod4 = 0;
		for (int i = 0; i < s.length(); i++) {
			mod4 *= 10;
			mod4 += s[i] - '0';
			mod4 %= 4;
		}
		if (mod4 != 2) { cout << 1 << endl; }
		else { cout << -1 << endl; }
	}
	return 0;
}
0