D - **GCD-Exreme(欧拉函数+数学分析,gcd转换) UVA - 11426

本文介绍了一种计算特定数学问题中G值的高效算法。G值定义为小于N的所有整数对的最大公约数之和。文章通过使用欧拉函数简化了问题,并提供了完整的C++实现代码。

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

Given the value of N, you will have to nd the value of G.The denition of G is given below:
G=i<N∑i=1jN∑j=i+1GCD(i; j)Here GCD(i; j)
means the greatest common divisor of integer i and integer j.For those who have trouble understanding summation notation, the meaning of G is given in the following code:
G=0;
for(i=1;i<N;i++)
for(j=i+1;j<=N;j++)
{
G+=gcd(i,j);
}
/*Here gcd() is a function that finds the greatest common divisor of the two input numbers
Input

The input le contains at most 100 lines of inputs. Each line contains an integer
N(1< N <4000001).
The meaning of N is given in the problem statement. Input is terminated by a line containing a single zero.

Output

For each line of input produce one line of output. This line contains the value of G for the corresponding N . The value of Gwill t in a 64-bit signed integer.


Sample Input
10
100
200000
0

Sample Output
67
13015
143295493160


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn =4000001;
int phi[maxn];
ll ans[maxn];
/******
思路分析:
令sn为前n相的和。。。
sn=s(n-1)+gcd(1,n)+gcd(2,n)+gcd(3,n)+....gcd(n-1,n);
令(Ps : 自己写展开后会发现这个规律)
fn=gcd(1,n)+...gcd(n-1,n);
设x属于[1,n-1]
gcd(x,n)=i; 可知:gcd(x,n)=i等价与gcd(x/i,n/i)*i;
令g(n,i)为gcd(x,n)=i的个数,又有可知的:gcd(x,n)==gcd(x/i,n/i)*i,(欧拉函数,小于等于n与n互质的数)
所以g(n,i)==i*phi(n/i);
所以 fn=sum(i*phi(n/i));
令j=n/i;
则
f(n)=f(i*j)=sum(i*phi[j]);
sn=f2+f3+f4+....+fn;
******/
/*************
推荐博客:http://blog.sina.com.cn/s/blog_77dc9e080101iao9.html
推荐博客:http://www.cnblogs.com/ITUPC/p/4912971.html

*************/
//求欧拉函数
void find_phi()
{
     ll i,j,k;
     for (i=0;i<maxn;i++)
     phi[i]=i;
     for (i=2;i<maxn;i++)
     {
         if(phi[i]==i)
         {
            for (j=i;j<maxn;j+=i)
            phi[j]=phi[j]/i*(i-1);
         }
     }
}
void solve ()
{
     memset(ans,0,sizeof(ans));
     ll i,j,k;
     for (i=2;i<maxn;i++)
     for (j=1;j*i<maxn;j++)
     {
         ans[i*j]+=j*phi[i];
     }
     ///更新为sn
     for (i=3;i<maxn;i++)
     ans[i]+=ans[i-1];

}

int main ()
{
     int n;
     find_phi();
     solve();
     while (~scanf("%d",&n))
     {
         if(!n)
         break;
         cout<<ans[n]<<endl;
//        ll a =0;
//        int i;
//        for (i=1;i<=n;i++)
//        a+=ans[i];
//        cout<<a<<endl;
    }
     return 0;
}


内容概要:本文深入探讨了DevOps流程落地中自动化测试与监控体系的构建,强调二者是保障软件质量和系统稳定性的重要支柱。自动化测试涵盖从单元测试到端到端测试的全流程自动化,而监控体系则通过实时采集和分析系统数据,及时发现并解决问题。文章介绍了测试金字塔模型的应用、监控指标的分层设计、测试与生产环境的一致性构建以及告警策略的精细化设置等核心技巧。此外,还提供了基于Python和Prometheus的具体代码案例,包括自动化接口测试脚本和监控指标暴露的实现,展示了如何在实际项目中应用这些技术和方法。 适合人群:对DevOps有一定了解,从事软件开发、运维或测试工作的技术人员,特别是那些希望提升自动化测试和监控能力的从业者。 使用场景及目标:①高并发业务系统中,模拟大规模用户请求,验证系统抗压能力和稳定性;②关键业务流程保障,确保金融交易、医疗数据处理等敏感业务的合规性和可追溯性;③微服务架构系统下,通过契约测试和分布式链路追踪,保证服务间的兼容性和故障快速定位。 阅读建议:本文不仅提供了理论指导,还有详细的代码示例,建议读者结合自身项目的实际情况,逐步实践文中提到的技术和方法,特别是在构建自动化测试框架和监控系统时,关注环境一致性、测试覆盖率和性能指标等方面。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值