CSES - Practice Contest 2024 - Results
Submission details
Task:Interesting number
Sender:asdf
Submission time:2024-09-28 12:07:23 +0300
Language:C++ (C++20)
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.01 sdetails
#2ACCEPTED0.01 sdetails

Code

#include <bits/stdc++.h>
using namespace std;
#define int long long

string to_string(string s) {
    return '"' + s + '"';
}
 
string to_string(const char* s) {
    return to_string((string) s);
}
 
string to_string(bool b) {
    return (b ? "true" : "false");
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
 
void debug_out() {
    cerr << endl;
}
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}
 
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

const int N = 2e5 + 5;

bool notprime[N];

void pre() {
    notprime[0] = notprime[1] = 1;
    for (int i = 2; i * i <= 1e5; i++) {
        if (!notprime[i]) {
            for (int j = i * i; j <= 1e5; j += i) {
                notprime[j] = 1;
            }
        }
    }
}

bool check(int x) {
    string s = to_string(x);
    string t = s;
    reverse(t.begin(), t.end());
    return s == t;
}

void solve() {
    int n;
    cin >> n;

    vector<int> a(n);
    for (int& i : a) cin >> i;

    for (int i : a) {
        if (check(i) && !notprime[i]) {
            cout << i << '\n';
            return;
        }
    }
}

signed main() {
    cin.tie(0)->sync_with_stdio(0);

    pre();
    
    int t;
    cin >> t;

    while (t--) {
        solve();
    }
}

Test details

Test 1

Verdict: ACCEPTED

input
1000
9
300 988 956 931 116 3 386 202 ...

correct output
3
3
181
919
191
...

user output
3
3
181
919
191
...
Truncated

Test 2

Verdict: ACCEPTED

input
1
100000
72 247 605 249 10 422 594 490 ...

correct output
191

user output
191