結果

問題 No.491 10^9+1と回文
ユーザー masa
提出日時 2017-03-10 23:41:08
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 670 bytes
コンパイル時間 630 ms
コンパイル使用メモリ 66,604 KB
実行使用メモリ 13,756 KB
最終ジャッジ日時 2024-06-24 09:02:04
合計ジャッジ時間 7,709 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 92 WA * 2 TLE * 3 -- * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>

using namespace std;

const long long mod = 1e9;

long long calc(long long a) {
	long long tmp = a;
	long long b = 0;
	while (tmp > 0) {
		b = b * 10 + tmp % 10;
		tmp /= 10;
	}

	b = b * mod + a;
	return b;
}

int main() {
	long long n;
	cin >> n;

	int a = n / mod;
	int b = n % mod;

	if (b < a) {
		a--;
	}

	// printf("%d %d\n", a, b);

	int ans = 0;
	for (int i = 0; i <= a; i++) {
		if ( i % 10 == 0) {
			continue;
		}

		long long val = calc(i);
		if (val <= n && (val / mod == val % mod)) {
// printf("%3d, %20lld\n", i, val);
			ans++;
		}

		if (val >= n * 10) {
			break;
		}
	}

	cout << ans << endl;
	return 0;
}
0