Submission #117045


Source Code Expand

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define pb push_back
#define mp make_pair
typedef long long ll;
const int inf = (1<<28);

vector<ll> ps;
void sieve(int n) {
  ps = vector<ll>(n);
  rep(i, n) ps[i] = i;
  ps[0] = ps[1] = 0;
  for(int i=2; i*i<=n; i++)
    if(ps[i])
      for(int j=i*i; j<n; j+=i)
        ps[j] = 0;
  ps.erase(remove(all(ps), 0), ps.end());
}

int main() {
  sieve(100000);
  
  ll n;
  while(cin >> n, n) {
    ll ans = -1;
    
    rep(i, ps.size()) {
      if(n % ps[i] == 0) ans = ps[i];
      while(n % ps[i] == 0) n /= ps[i];
    }
    
    if(n != 1) ans = n;
    
    cout << ans << endl;
  }
}

Submission Info

Submission Time
Task B - Working for the World
User suminos
Language C++ (G++ 4.6.4)
Score 100
Code Size 851 Byte
Status AC
Exec Time 30 ms
Memory 2464 KB

Judge Result

Set Name All
Score / Max Score 100 / 100
Status
AC × 27
Set Name Test Cases
All 00-sample, 10-minimum, 11-maximum, 12-little, 13-large, 14-middle, 15-zero, 50-random00, 50-random01, 50-random02, 50-random03, 50-random04, 50-random05, 50-random06, 50-random07, 50-random08, 50-random09, 50-random10, 50-random11, 50-random12, 50-random13, 50-random14, 50-random15, 50-random16, 50-random17, 50-random18, 50-random19
Case Name Status Exec Time Memory
00-sample AC 26 ms 2340 KB
10-minimum AC 25 ms 2344 KB
11-maximum AC 25 ms 2332 KB
12-little AC 27 ms 2332 KB
13-large AC 27 ms 2464 KB
14-middle AC 30 ms 2328 KB
15-zero AC 25 ms 2460 KB
50-random00 AC 27 ms 2340 KB
50-random01 AC 27 ms 2344 KB
50-random02 AC 28 ms 2332 KB
50-random03 AC 26 ms 2460 KB
50-random04 AC 28 ms 2344 KB
50-random05 AC 27 ms 2336 KB
50-random06 AC 27 ms 2340 KB
50-random07 AC 27 ms 2460 KB
50-random08 AC 27 ms 2340 KB
50-random09 AC 28 ms 2344 KB
50-random10 AC 27 ms 2464 KB
50-random11 AC 27 ms 2460 KB
50-random12 AC 27 ms 2464 KB
50-random13 AC 26 ms 2272 KB
50-random14 AC 26 ms 2456 KB
50-random15 AC 27 ms 2332 KB
50-random16 AC 27 ms 2336 KB
50-random17 AC 27 ms 2464 KB
50-random18 AC 27 ms 2348 KB
50-random19 AC 27 ms 2464 KB