fork download
  1. #include <bits/stdc++.h>
  2. #define FOR(i, a, b) for(int i = (a), _b = (b); i <= _b; ++i)
  3. #define fi first
  4. #define se second
  5. #define el "\n"
  6. #define pb push_back
  7. #define sz(a) (int)a.size()
  8. #define FILL(a, x) memset(a, x, sizeof(a))
  9.  
  10. using namespace std;
  11. typedef long long ll;
  12. typedef pair<int, int> ii;
  13. const int N = (int)1e6+3, MAX = (int)1e6;
  14. int T;
  15. int P[N];
  16.  
  17. void Sieve(){
  18. P[1] = 1;
  19. for(int i = 2; i*i <= MAX; i++)
  20. if (!P[i])
  21. for(int j = 2*i; j <= MAX; j += i)
  22. if (!P[j]) P[j] = i;
  23. FOR(i, 2, MAX)
  24. if (!P[i]) P[i] = i;
  25. }
  26.  
  27. bool Check(int x){
  28. int L, cnt, p;
  29. L = cnt = p = 0;
  30. while(x > 1){
  31. p = P[x];
  32. cnt = 0;
  33. while(x%p==0){
  34. cnt++;
  35. x /= p;
  36. if (cnt > 1) return 0;
  37. }
  38. L++;
  39. if (L > 2) return 0;
  40. }
  41. return (L == 2);
  42. }
  43.  
  44. int main()
  45. {
  46. ios_base::sync_with_stdio(false);
  47. cin.tie(NULL); cout.tie(NULL);
  48. freopen("PRIME.inp", "r", stdin);
  49. freopen("PRIME.out", "w", stdout);
  50. Sieve();
  51. cin>>T;
  52. while(T--){
  53. int x;
  54. cin>>x;
  55. while(!Check(x)) x--;
  56. cout<<x<<el;
  57. }
  58. return 0;
  59. }
  60.  
Success #stdin #stdout 0.01s 7772KB
stdin
Standard input is empty
stdout
Standard output is empty