Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as C++ by anonimus123123 ( 13 years ago )
#include <iostream>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cassert>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <sstream>
#include <list>
#include <bitset>
using namespace std;
#define fore(i, l, r) for(int i = int(l); i < int(r); ++i)
#define forn(i, n) fore(i, 0, n)
#define X first
#define Y second
#define sz(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define mp make_pair
template<typename T> inline T abs(T a) { return a < 0 ? -a : a; }
template<typename T> inline T sqr(T a) { return a * a; }
typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;
const int INF = int(1e9) + 7;
const ld EPS = 1e-9;
const ld PI = acos(-1.0);
const int NMAX = 2000000;
int used[NMAX], pos[NMAX], ok[NMAX];
int get(int p){
while(pos[ok[p]] != -1){
ok[p] += p;
}
return ok[p];
}
int itok = -1;
int nok(){
while(pos[itok] != -1)
itok++;
return itok;
}
void init(){
memset(used, -1, sizeof used);
memset(pos, -1, sizeof pos);
fore(i, 2, NMAX){
if(used[i] != -1)
continue;
ok[i] = i;
used[i] = i;
if(i * li(i) < NMAX){
for(int j = i * i; j < NMAX; j += i)
used[j] = i;
}
}
pos[1] = 0;
pos[2] = 1;
itok = 1;
int prev = 2, sza = 2;
while(nok() <= 300000){
int minv = INF;
for(int val = prev; val != 1; val = val / used[val]){
int p = used[val];
minv = min(minv, get(p));
}
pos[minv] = sza++;
prev = minv;
// if(sza < 30)
// cerr << minv << " ";
}
// cerr << endl;
}
int main(){
#ifdef ssu1
freopen("input.txt", "r", stdin);
#endif
cout.precision(20); cout << fixed;
cerr.precision(5); cerr << fixed;
init();
int n;
while(scanf("%d", &n) != EOF){
if(n == 0)
break;
printf("The number %d appears in location %d.\n", n, pos[n] + 1);
}
#ifdef ssu1
cerr << "Time = " << clock() << endl;
#endif
return 0;
}
Revise this Paste