-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathdiff_Main.cpp
More file actions
54 lines (51 loc) · 1.03 KB
/
Copy pathdiff_Main.cpp
File metadata and controls
54 lines (51 loc) · 1.03 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
diff --git a/CodeJam/Main.cpp b/examples/2021/Round2/B/Main.cpp
index 2150379..a04950d 100644
--- a/CodeJam/Main.cpp
+++ b/examples/2021/Round2/B/Main.cpp
@@ -1570,11 +1570,49 @@ void init(){
cin >> T;
}
+ll N;
+
void readInput(){
+ cin >> N;
+}
+
+v(ll) memory(1000001, -1);
+
+v(ll) getpf(ll n){
+ v(ll) res;
+ fornn(d, 2, sqrtl(n)+1){
+ if(n%d==0){
+ res.pb(d);
+ res.pb(n/d);
+ }
+ }
+ return res;
+}
+
+ll recur(ll n){
+ if(n<=1) return -1;
+ if(memory[n] != -1) return memory[n];
+ v(ll) pf = getpf(n);
+ memory[n] = 1;
+ foreach(p, pf){
+ ll curresult = recur(n/p - 1);
+ memory[n] = max(memory[n], curresult+1);
+ }
+ return memory[n];
}
// write to COMM_TYPE result
void calcFunction() {
+ v(ll) pf = getpf(N);
+ lg(pf);
+ result = 1;
+ foreach(p, pf){
+ if(p==2) continue;
+ ll curresult = recur(N/p - 1);
+ lg(p);
+ lg(curresult);
+ result = max(result, curresult+1);
+ }
}
} // namespace task