Advertisement
Asif_Anwar

Untitled

Oct 30th, 2020
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. #define ll long long
  5. #define pb push_back
  6. int prime[10005];
  7. void sieve()
  8. {
  9. prime[0] = prime[1] = 1;
  10. for(int i=2; i*i<=10005; i++) {
  11. if(prime[i]==0) {
  12. for(int j=2*i; j<=10005; j+=i) {
  13. prime[j] = 1;
  14. }
  15. }
  16. }
  17. }
  18.  
  19. ll stringToN(string s)
  20. {
  21. int sz = s.size();
  22. ll num = 0;
  23. for(int i=0; i<sz; i++) {
  24. num = num*10 + (s[i]-'0');
  25. }
  26. return num;
  27. }
  28.  
  29. int main()
  30. {
  31. int t;
  32. cin >> t;
  33. int cnt = 1;
  34. sieve();
  35. while(t--) {
  36. int n;
  37. cin >> n;
  38. cin.ignore();
  39. string str;
  40. cin >> str;
  41. ll mx = -1;
  42. for(int i=0; i<n; i++) {
  43. for(int j=1; j<=10; j++) {
  44. //cout << str.substr(i, j) << endl;
  45. //cout << stringToN(str.substr(i, j)) << "\n\n";
  46. ll x = stringToN(str.substr(i, j));
  47. //cout << x << endl;
  48. if(x>10000) continue;
  49. if(!prime[(int)x]) {
  50. if(mx<x && x<10000) {
  51. mx = x;
  52. }
  53. }
  54. }
  55. }
  56. cout << "Case " << cnt << ": ";
  57. if(mx==-1) cout << "This is a junk!\n";
  58. else {
  59. cout << mx << endl;
  60. }
  61. cnt++;
  62. }
  63. return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement