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

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.

Examples

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.

题意

给你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;
}
posted @ 2019-09-02 00:20  qscqesze  阅读(328)  评论(0编辑  收藏  举报