qscqesze
Published on 2017-09-02 11:31 in 暂未分类 with qscqesze

# G. Polygons

## Description

You are given two integers 𝑛 and 𝑘.

You need to construct 𝑘 regular polygons having same circumcircle, with distinct number of sides 𝑙 between 3 and 𝑛.

Illustration for the first example.
You can rotate them to minimize the total number of distinct points on the circle. Find the minimum number of such points.

## Input

The only line of input contains two integers 𝑛 and 𝑘 (3≤𝑛≤106, 1≤𝑘≤𝑛−2), the maximum number of sides of a polygon and the number of polygons to construct, respectively.

## Output

Print a single integer — the minimum number of points required for 𝑘 polygons.

input

6 2

output

6

input

200 50

output

708

## Note

In the first example, we have 𝑛=6 and 𝑘=2. So, we have 4 polygons with number of sides 3, 4, 5 and 6 to choose from and if we choose the triangle and the hexagon, then we can arrange them as shown in the picture in the statement.

Hence, the minimum number of points required on the circle is 6, which is also the minimum overall possible sets.

## 代码

#include<bits/stdc++.h>
using namespace std;
int n,k;
const int maxn = 1e6+7;
int phi[maxn];
void get_phi(int n){
iota(phi,phi+n+1,0);
for(int i=2;i<=n;i++){
if(phi[i]==i){
phi[i]=i-1;
for(int j=2*i;j<=n;j+=i){
phi[j]=(phi[j]/i)*(i-1);
}
}
}
}
int main(){
cin>>n>>k;
if(k==1){
cout<<"3"<<endl;
return 0;
}
k=k+2;
get_phi(n);
sort(phi+1,phi+1+n);
cout<<accumulate(phi+1,phi+1+k,0ll)<<endl;
}
posted @ 2019-09-02 00:20  qscqesze  阅读(191)  评论(0编辑  收藏