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

本文探讨了一个数学问题:如何从3到n的正多边形中选取k个,使它们在共用同一外接圆时,点数达到最小。通过分析发现,若b是a的因子,则选择a后再选b不会增加额外点数。文章提供了一种解决方案,即计算所有正多边形的不同分数的个数,并给出了相应的代码实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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;
}

转载于:https://www.cnblogs.com/qscqesze/p/11444385.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值