Submission

Status:

PPPPPPPPPPPPPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: loop

Problemset: จำนวนเฉพาะก่อนหน้า

Language: cpp

Time: 0.004 second

Submitted On: 2026-10-10 18:33:54

#include <iostream>
#include <string>
using namespace std;

bool prime(long long x) {
    if (x < 2) return false;
    if (x % 2 == 0) return x == 2;
    for (long long d = 3; d * d <= x; d += 2)
        if (x % d == 0) return false;
    return true;
}

// The statement calls N a real number; the primes must be strictly below it.
int main() {
    string s;
    cin >> s;
    long long whole = 0;
    bool frac = false, dot = false;
    for (int i = 0; i < (int)s.size(); i++) {
        if (s[i] == '.') { dot = true; continue; }
        if (s[i] < '0' || s[i] > '9') continue;
        if (!dot) whole = whole * 10 + (s[i] - '0');
        else if (s[i] != '0') frac = true;
    }
    long long x = frac ? whole : whole - 1;      // largest integer below N
    long long found[5];
    int k = 0;
    while (k < 5 && x >= 2) {
        if (prime(x)) found[k++] = x;
        x--;
    }
    for (int i = k - 1; i >= 0; i--) cout << found[i] << (i > 0 ? ' ' : '\n');
    return 0;
}