-
Notifications
You must be signed in to change notification settings - Fork 0
/
nuts_frenzy1.cpp
122 lines (95 loc) · 2.01 KB
/
nuts_frenzy1.cpp
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include <iostream>
#include <vector>
#include <cmath>
#include <cstdio>
#include<cstdlib>
using namespace std;
void prime_generator( vector<int> &prime );
bool is_prime( int n );
void print( vector<int> v );
int prime_div(long long int &k, int p );
long long int sum_of_factors( long long int k, vector<int> prime );
int time_taken( long long int k, long long int rate);
int main()
{
vector<int> prime;
prime_generator( prime );
int t;
cin >> t;
srand(127);
for ( int i = 0; i < t; i++ ) {
long long int k;
long long int i;
long long int f;
k = rand();
i = rand()%1000000;
f = rand()%100;
cout<<k <<" "<< i <<" "<< f<<endl;
cout << time_taken(k, i) << " ";
if ( f != 0 ) {
cout << time_taken(k, (k/f)) << " ";
} else {
cout << k << " ";
}
cout << time_taken(k, sum_of_factors(k, prime) - k - 1) << endl;
//getchar();
}
return 0;
}
void prime_generator( vector<int> &prime ) {
prime.push_back(2);
for ( int i = 3; i < 32000; i++ ) {
if ( is_prime(i) ) {
prime.push_back(i);
}
}
// cout << " prime size " << prime.size() << endl;
}
bool is_prime( int n ) {
for ( int i = 2; i < sqrt(n) + 1; i++ ) {
if ( n % i == 0 ) {
return false;
}
}
return true;
}
long long int sum_of_factors( long long int k, vector<int> prime ) {
long long int sum = 1;
for ( int i = 0; ( i < prime.size() && prime[i] <= k ); i++ ) {
// cout << i << " " << prime[i] << endl;
int n = prime_div(k, prime[i] );
sum *= ( ( pow(prime[i], n + 1) - 1 ) / (prime[i] - 1) );
}
if ( k != 1 ) {
sum *= ( (k*k - 1 ) / (k - 1) );
}
return sum;
}
int prime_div(long long int &k,int p ) {
int ctr = 0;
if ( k <= 1) {
return ctr;
}
while ( k % p == 0 ) {
ctr++;
k = k / p;
}
return ctr;
}
void print( vector<int> v ) {
for ( int i = 0; i < v.size(); i++ ) {
cout << v[i] << endl;
getchar();
}
}
int time_taken( long long int k, long long int rate ) {
int time = 0;
if ( rate <= 1 ) {
rate = 1;
}
time = k / rate;
if ( k % rate != 0 ) {
time++;
}
return time;
}