博客
关于我
P2568 GCD(欧拉函数)
阅读量:713 次
发布时间:2019-03-21

本文共 528 字,大约阅读时间需要 1 分钟。

为了解决问题,我们需要计算从1到n的所有数对(i, j)中,i和j的最大公约数为p的数目。通过分析和应用数论中的欧拉函数,我们可以得出以下结论:

分析与解答

  • 问题转化:题目要求计算满足gcd(i, j) = p的数对(i, j)的数量。我们可以将问题转化为寻找互质的数对(a, b),其中i = p * a,j = p * b。

  • 限制条件:为了满足gcd(i, j) = p,a和b必须互质,并且1 ≤ a, b ≤ n/p。令m = floor(n/p)。

  • 欧拉函数的应用:欧拉函数φ(m)计算小于等于m的自然数中与m互质的数的个数。由于a和b必须互质,每对(a, b)满足条件的次数为φ(1) + φ(2) + ... + φ(m)。

  • 公式推导:因此,满足gcd(i, j) = p的数对个数为φ(1) + φ(2) + ... + φ(m),即φ(1) + φ(2) + ... + φ(m)。

  • 答案

    ∑从i = 1到floor(n/p),再计算每一项φ(i),即最终的总数为:

    ∑ i = 1 到 floor(n/p) φ(i)

    简化为:

    ∑_{i=1}^{n/p} φ(i),其中floor(n/p) = m。因此,答案为欧拉函数从1到m的求和。

    转载地址:http://iijrz.baihongyu.com/

    你可能感兴趣的文章
    NN&DL4.7 Parameters vs Hyperparameters
    查看>>
    NN&DL4.8 What does this have to do with the brain?
    查看>>
    nnU-Net 终极指南
    查看>>
    No 'Access-Control-Allow-Origin' header is present on the requested resource.
    查看>>
    No 'Access-Control-Allow-Origin' header is present on the requested resource.
    查看>>
    NO 157 去掉禅道访问地址中的zentao
    查看>>
    no available service ‘default‘ found, please make sure registry config corre seata
    查看>>
    No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
    查看>>
    no connection could be made because the target machine actively refused it.问题解决
    查看>>
    No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
    查看>>
    No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
    查看>>
    No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
    查看>>
    No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
    查看>>
    No mapping found for HTTP request with URI [/logout.do] in DispatcherServlet with name 'springmvc'
    查看>>
    No module named 'crispy_forms'等使用pycharm开发
    查看>>
    No module named cv2
    查看>>
    No module named tensorboard.main在安装tensorboardX的时候遇到的问题
    查看>>
    No module named ‘MySQLdb‘错误解决No module named ‘MySQLdb‘错误解决
    查看>>
    No new migrations found. Your system is up-to-date.
    查看>>
    No qualifying bean of type XXX found for dependency XXX.
    查看>>