/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 3ms 2.062 MiB
#2 Accepted 3ms 2.062 MiB
#3 Accepted 3ms 2.062 MiB
#4 Accepted 3ms 2.066 MiB
#5 Accepted 188ms 2.391 MiB
#6 Accepted 369ms 2.305 MiB
#7 Accepted 361ms 2.32 MiB
#8 Accepted 136ms 2.293 MiB

Code

#include <bits/stdc++.h>
using namespace std;
#define int long long
int prime[500000],nprime=1;
int mark[500000],pal[500005];
vector<int>primes;
void sieve(int n){
    int i,j,limit=sqrt(n*1)+2;
    mark[1]=1;
    for(i=4;i<=n;i+=2)mark[i]=1;
    prime[2]=nprime;
    nprime++;
    primes.push_back(2);
    for(i=3;i<=n;i+=2){
            if(!mark[i]){
                    primes.push_back(i);
                    prime[i]=nprime;
                    nprime++;
                    if(i<=limit){
                            for(j=i*i;j<=n;j+=i*2){
                                    mark[j]=1;
                            }
                    }
            }
    }
}

int32_t main () {
  cin.tie(0)->sync_with_stdio(0);
  int t = 1;
  cin >> t;
  sieve(1e5);
  while (t--) {
      int n, x, ans = INT_MAX;
      cin >> n;
      if (n%2) {
          ans = n;
          for (int i = 0; primes[i]*primes[i] <= n; i++) {
              if (n%primes[i] == 0) {
                  ans = min (ans, primes[i]);
              }
          }
          ans = n/ans;
      }
      else ans = n/2;
      cout << ans << "\n";
  }
}

Information

Submit By
Type
Submission
Problem
P1052 Yet Another Array Partition
Contest
Brain Booster #3
Language
C++20 (G++ 13.2.0)
Submit At
2024-05-06 15:34:01
Judged At
2024-11-11 03:34:06
Judged By
Score
100
Total Time
369ms
Peak Memory
2.391 MiB