-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCubPrim.cpp
More file actions
71 lines (62 loc) · 1.54 KB
/
Copy pathCubPrim.cpp
File metadata and controls
71 lines (62 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <fstream>
#include <algorithm>
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;
const unsigned long VMAX = 2642245;
ifstream fin("cubprim.in");
ofstream fout("cubprim.out");
ll N, M, i, j, tmp, ciur[VMAX + 5];
ull x;
struct elem {
int index;
ll root;
ull value;
} v[200005];
inline ll cubeRoot( const ull &X ) {
if (!X) return 0;
ull st = 1, dr = VMAX, mid;
while ( st <= dr ) {
mid = ( st + dr ) >> 1;
if ( 1ULL * mid * mid * mid == X )
return mid;
else if ( 1ULL * mid * mid * mid < X )
st = mid + 1;
else
dr = mid - 1;
}
return -1;
}
inline bool cmp( const elem &A, const elem &B ) {
if ( A.value == B.value )
return A.index < B.index;
return A.value > B.value;
}
int main() {
unsigned long sqr = sqrt( VMAX );
for ( i = 4; i <= VMAX; i += 2 )
ciur[i] = 1;
for ( i = 3; i <= sqr; i += 2 )
if ( !ciur[i] )
for ( j = i * i; j <= VMAX; j += 2 * i )
ciur[j] = 1;
fin >> N;
M = 0;
for ( i = 1; i <= N; i++ ) {
fin >> x;
tmp = cubeRoot( x );
if ( tmp != -1 && ciur[tmp] == 0 ) {
M++;
v[M].index = i;
v[M].root = tmp;
v[M].value = x;
}
}
fout << M << '\n';
sort( v + 1, v + M + 1, cmp );
for ( i = 1; i <= M; i++ )
fout << v[i].index << ' ' << v[i].root << ' ' << v[i].value << '\n';
fin.close();
fout.close();
return 0;
}