-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStrange Function.cpp
More file actions
79 lines (58 loc) · 1.09 KB
/
Strange Function.cpp
File metadata and controls
79 lines (58 loc) · 1.09 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
#include<iostream>
using namespace std;
#define int long long
const int modulo = 1e9 + 7;
int gcd(int x, int y) {
while(y){int r = x%y; x = y; y = r;}
return x;
}
int lcm(int x, int y) {
return (x / gcd(x, y)) * y;
}
// f(i)
int f(int i){
int ans = 0;
int j = 1;
while(i%j == 0){
j++;
ans++;
}
ans++;
return ans;
}
//Strange Function
int strangeFunction(){
int n;
cin>>n;
int res = 0;
for(int i = 1; i<=n; i++){
res += f(i);
}
//cout<<"ans = ";
return res % modulo;
}
// Strange Function 2.0
int sFunction(){
int n;
cin >> n;
int lcm = 1;
int ans = 0;
for (int i = 2; ; i++) {
int b = n / lcm;
lcm = lcm * i / gcd(lcm, i);
int a = n / lcm;
ans += (b - a) * i;
ans %= modulo;
if (lcm > n) break;
}
//cout<<"ans = ";
return ans;
}
signed main(){
int tc = 1;
cin >> tc;
while (tc--) {
//cout<<strangeFunction()<<endl;
cout<<sFunction()<<endl;
}
}