結果

問題 No.491 10^9+1と回文
ユーザー はまやんはまやん
提出日時 2017-03-11 00:02:26
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 6 ms / 1,000 ms
コード長 2,383 bytes
コンパイル時間 1,372 ms
コンパイル使用メモリ 167,444 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-01 08:22:32
合計ジャッジ時間 3,690 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 103
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)




#define rrep(i,a,b) for(int i=a;i>=b;i--)
typedef long long ll;
ll N;
//-----------------------------------------------------------------
int main() {
	cin >> N;

	int ans = 0;
	rep(i, 1, 101010) {
		string s = to_string(i);
		int n = s.length();

		/*bool ng = false;
		rep(j, 0, n) if (s[j] == '0') ng = true;
		if (ng) continue;*/

		// 奇数
		ll x = 0;
		rep(i, 0, n - 1) x = x * 10 + s[i] - '0';
		x = x * 10 + s[n - 1] - '0';
		rep(i, 0, n - 1) x = x * 10 + s[n - 2 - i] - '0';
		//cout << x << endl;
		int nx = (n - 1) * 2 + 1;
		ll a = x;
		rep(i, 0, 9) a *= 10;
		a += x;

		if (a < 0) continue;

		if (a <= N) {
			//printf("%lld\n", a);
			ans++;
		}

		// 偶数
		ll xx = 0;
		rep(i, 0, n) xx = xx * 10 + s[i] - '0';
		rep(i, 0, n) xx = xx * 10 + s[n - 1 - i] - '0';
		//cout << xx << endl;
		int nxx = n * 2;
		ll b = xx;
		rep(i, 0, 9) b *= 10;
		b += xx;

		if (b < 0) continue;
		
		if (b <= N) {
			//printf("%lld\n", b);
			ans++;
		}
	}

	cout << ans << endl;
	return 0;


	/*

	ll mo = 1000000001;

	int dig = 0;
	ll t = N;
	while (0 < t) dig++, t /= 10;

	ll ans = 0;
	rrep(i, 8, 1) {
		ll cc = 0;
		int d = i + 2 * (9 - i);
		if (d < dig) {
			// 全部OK
			int j = 9 - i;

			if (j == 1) {
				cc = 9;
			}
			else if (j % 2 == 0) {
				int k = j / 2 - 1;
				ll c = 9;
				rep(kk, 0, k) c *= 9;
				cc += c;
			}
			else {
				int k = j / 2;
				ll c = 9;
				rep(kk, 0, k) c *= 9;
				cc += c;
			}
		}
		else if (d == dig) {
			// 一部OK
			int j = 9 - i;

			string n = to_string(N);
			int ma = 0;
			rep(i, 0, j) ma = ma * 10 + n[i] - '0';

			int mi = 0;
			rep(i, 0, j) mi = mi * 10 + 1;

			if (mi < ma) {
				//if(j % 2 == 0)

				rep(x, mi, ma) {
					string s = to_string(x);
					bool ok = true;
					rep(i, 0, s.length() / 2 + 1) {
						int j = s.length() - 1 - i;
						if (s[i] != s[j]) ok = false;
						if (s[i] == '0') ok = false;
					}
					if (ok) cc++;
				}
			}

			ll th = ma;
			rep(i, 0, d - j * 2) th *= 10;
			int y = ma;
			while (0 < y) {
				th = th * 10 + y % 10;
				y /= 10;
			}

			if (th <= N) cc++;

			//cout << th << endl;

			//printf("[%d %d]\n", mi, ma);
		}

		ans += cc;
		//if(0 < cc) printf("%d -> %lld\n", d, cc);
	}
	cout << ans << endl;*/

	ll mo = 1000000001;
	rep(i, 1, 1000) {
		printf("%lld\n", mo * i);
	}
}
0