結果

問題 No.3485 Find 495-like Number
コンテスト
ユーザー cho435
提出日時 2026-03-27 23:55:24
言語 C++23(gnu拡張)
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 64 ms / 5,000 ms
コード長 1,279 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,481 ms
コンパイル使用メモリ 378,676 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2026-03-27 23:55:44
合計ジャッジ時間 11,071 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_1
外部呼び出し有り
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#include <atcoder/all>

using namespace std;
using ll = long long;
#define rep(i, s, t) for (ll i = s; i < (ll)(t); i++)
#define all(x) begin(x), end(x)
template <class T> bool chmin(T& x, T y) {
	return x > y ? (x = y, true) : false;
}
template <class T> bool chmax(T& x, T y) {
	return x < y ? (x = y, true) : false;
}

// rho
char f_buf[256];
vector<ll> factor(ll n) {
	string cmd = "factor " + to_string(n);
	FILE* p = popen(cmd.c_str(), "r");
	assert(p);
	assert(fgets(f_buf, sizeof(f_buf), p));
	pclose(p);
	vector<ll> v;
	stringstream ss(f_buf);
	ss.ignore(sizeof(f_buf), ':');
	while (ss >> n) v.push_back(n);
	return v;
}

void solve() {
	ll l, r;
	cin >> l >> r;
	chmax(l, 315LL);
	rep(x, l, r + 1) {
		if (x % 2 == 0) continue;
		int flg = 0;
		for (int d : {3, 5, 7, 11, 13, 17, 19, 23}) {
			if (x % d == 0) {
				if (x % (d * d) == 0 && factor(x / (d * d)).size() == 2) {
					cout << x << '\n';
					return;
				}
				flg = 1;
				break;
			}
		}
		if (!flg) {
			auto v = factor(x);
			if (v.size() == 4 && v[0] == v[1]) {
				cout << x << '\n';
				return;
			}
		}
	}
	cout << "-1\n";
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(15);
	int t = 1;
	// cin >> t;
	while (t--) solve();
}
0