Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2) G. Polygons 數論

G. Polygons

Description

You are given two integers 𝑛 and 𝑘.c++

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

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.ui

Output

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

Examples

inputcode

6 2ip

outputci

6get

inputinput

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.

題意

給你n和k,讓你從3~n個點的正多邊形中選出k個,使得他們在同一個外接圓的狀況下,點數最少。

題解

簡單的思考,若是b是a的因子,那麼在同一個外接圓的狀況下,已經選了a,再選個b確定不會多任何一個點的。

首先一個,咱們定一個圓上的公共點P;那麼對於每個正多變形k在圓上的點分別離P的距離爲1/k,2/k,3/k....,k-1/k。

那麼這道題的答案就是全部的正多邊形的不一樣的分數的個數。

在保證選A以前,A的全部因子都已經被選擇的狀況下,那麼答案實際上就是歐拉函數的和。

代碼

#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;
}
相關文章
相關標籤/搜索