-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmobius.cpp
61 lines (50 loc) · 1.04 KB
/
mobius.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
// https://www.acmicpc.net/problem/1557
#include <iostream>
#include <algorithm>
#include <limits>
#include <vector>
#include <string>
#include <map>
using std::cin; using std::cout;
using ull = unsigned long long;
using pii = std::pair<int, int>;
const int INF = std::numeric_limits<int>::max();
const long long MAX = 100000;
std::map<int, int> arr;
void mu()
{
arr[1] = 1;
for(long long i = 1; i <= MAX; ++i)
{
for(long long j = i*2; j <= MAX; j += i)
{
arr[j] -= arr[i];
}
}
}
long long count(long long n)
{
long long ret = 0;
for(long long i = 1; i*i <= n; ++i)
{
ret += arr[i] * (n /(i*i));
}
return ret;
}
int main()
{
std::ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
mu();
long long k; cin >> k;
long long l = 0, r = k*2;
while(l<r)
{
long long mid = (l+r)/2;
if(count(mid) < k) l = mid+1;
else r = mid;
}
cout << r << '\n';
}//g++ -o a -std=c++17 *.cpp
// https://ohgym.tistory.com/19
// https://eine.tistory.com/entry/이진-탐색-이분-탐색binary-search-구현시-고려할-것들