Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define pb push_back
- int prime[10005];
- void sieve()
- {
- prime[0] = prime[1] = 1;
- for(int i=2; i*i<=10005; i++) {
- if(prime[i]==0) {
- for(int j=2*i; j<=10005; j+=i) {
- prime[j] = 1;
- }
- }
- }
- }
- ll stringToN(string s)
- {
- int sz = s.size();
- ll num = 0;
- for(int i=0; i<sz; i++) {
- num = num*10 + (s[i]-'0');
- }
- return num;
- }
- int main()
- {
- int t;
- cin >> t;
- int cnt = 1;
- sieve();
- while(t--) {
- int n;
- cin >> n;
- cin.ignore();
- string str;
- cin >> str;
- ll mx = -1;
- for(int i=0; i<n; i++) {
- for(int j=1; j<=10; j++) {
- //cout << str.substr(i, j) << endl;
- //cout << stringToN(str.substr(i, j)) << "\n\n";
- ll x = stringToN(str.substr(i, j));
- //cout << x << endl;
- if(x>10000) continue;
- if(!prime[(int)x]) {
- if(mx<x && x<10000) {
- mx = x;
- }
- }
- }
- }
- cout << "Case " << cnt << ": ";
- if(mx==-1) cout << "This is a junk!\n";
- else {
- cout << mx << endl;
- }
- cnt++;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement