CSES - Practice Contest 2024 - Results
Submission details
Task:Interesting number
Sender:GenericTeamname
Submission time:2024-09-28 14:17:18 +0300
Language:C++ (C++11)
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.01 sdetails
#2ACCEPTED0.03 sdetails

Code

#include <bits/stdc++.h>

using namespace std;
#define int long long

// g++ <filename>.cpp -g -Wall -Wextra -DDEBUG -o <executable>

// copied from: https://codeforces.com/blog/entry/79024
// === Debug macro starts here ===

int recur_depth = 0;
#ifdef DEBUG
#define dbg(x) {++recur_depth; auto x_=x; --recur_depth; cerr<<string(recur_depth, '\t')<<"\e[91m"<<__func__<<":"<<__LINE__<<"\t"<<#x<<" = "<<x_<<"\e[39m"<<endl;}
#else
#define dbg(x)
#endif
template<typename Ostream, typename Cont>
typename enable_if<is_same<Ostream,ostream>::value, Ostream&>::type operator<<(Ostream& os,  const Cont& v){
	os<<"[";
	for(auto& x:v){os<<x<<", ";}
	return os<<"]";
}
template<typename Ostream, typename ...Ts>
Ostream& operator<<(Ostream& os,  const pair<Ts...>& p){
	return os<<"{"<<p.first<<", "<<p.second<<"}";
}

// === Debug macro ends here ===

bool is_prime(int n) {

    if (n < 2) return false;

    for (int i = 2; i < n; i++) {
      
        if (n % i == 0) {
            return false;
        }
    }

    return true;
}

bool is_palindrome (int n) {

    string s = to_string(n);
    string s_reversed = s;
    reverse(s_reversed.begin(), s_reversed.end());

    return !s.compare(s_reversed);;
}

signed main() {
    
    int t;
    cin >> t;
    
    for (int i = 0; i < t; i++) {
        int n;
        cin >> n;

        for (int j = 0; j < n; j++) {
            int number;
            cin >> number;

            // cout << number << ": Prime: " << is_prime(number) << "\n";

            if (is_palindrome(number) && is_prime(number)) {
                cout << number << "\n";
            }
        
        }
    }

    return 0;
}

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