-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHcrank_breaking_sticks.cpp
More file actions
executable file
·80 lines (70 loc) · 1.63 KB
/
Hcrank_breaking_sticks.cpp
File metadata and controls
executable file
·80 lines (70 loc) · 1.63 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
72
73
74
75
76
77
78
79
80
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstring>
using namespace std;
long long prime(long long int n)
{
long long int max = 1 ;
while (n%2 == 0)
{ max = 2 ;
n = n/2;
}
for ( long long int i = 3; i <= sqrt(n); i = i+2)
{
while (n%i == 0)
{
n = n/i;
max = i ;
}
}
if( n > max)
max = n ;
return max ;
}
long long int a[103];
long long int rec( long long int n)
{
if(n <= 100)
return a[n] ;
long long int p =prime(n) ;
return (p*rec(n/p)) + 1 ;
}
int main() {
memset(a , 0 , sizeof(a) );
long long int n;
cin >> n;
a[0] = 0 ;
a[1] = 1 ;
a[2] = 3 ; a[3] = 4 ;
long long int max =0, flag = 0 , temp = 0 ;
for(int i=4 ; i< 102 ; i++)
{ max = 0 ; flag =0 ; temp = 0 ;
for( int j =2 ; j < i ; j++)
{
if( i %j == 0 )
{
temp = j* a[i/j] + 1 ;
flag = 1 ;
}
if( max < temp )
max = temp ;
}
a[i] = max ;
if(flag == 0)
{
a[i] = i + 1 ;
}
}
long long sum = 0 ;
long long res ;
for ( long long int i = 0;i < n;i++) {
cin >> res;
sum += rec(res) ;
}
cout << sum ;
return 0;
}