Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
431815 方相宜 【C6-10】素数的最短距离 C++ 通过 100 117 MS 256 KB 703 2026-03-12 20:00:39

Tests(1/1):


#include <iostream> using namespace std; bool hsg(int x) { if (x < 2) return false; for (int i = 2; i * i <= x; ++i) { if (x % i == 0) return false; } return true; } int main() { int N, M; cin >> N; while (N--) { cin >> M; if (hsg(M)) { cout << M << endl; continue; } int l = M - 1, r = M + 1; while (true) { if (hsg(l)) { cout << l << endl; break; } if (hsg(r)) { cout << r << endl; break; } l--; r++; } } return 0; }


测评信息: