UVALive5964 LCM Extreme && UVA11426 GCD - Extreme (II) 欧拉函数筛法

限时加码!20+主流AI编程工具免费用 购周边加赠Coding Plan Lite,Claude Code、Cursor等即刻畅享,学习进阶更高效! 阅读详情

UVALive5964 LCM Extreme 点击打开链接

UVA11426 GCD - Extreme (II)  点击打开链接



#include <iostream>
#include <cstdio>
#include <map>
#include <cmath>
#include <map>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
using namespace std;
#define LL unsigned long long
#define maxn 5000005
LL mod=1<<64;
LL euler[maxn+5];
LL f[maxn+5];
void euler_init(){
    memset(f,0,sizeof(f));
    for(int i=0;i<=maxn;i++) euler[i]=i;
    for(int i=2;i<=maxn;i++){
        if(euler[i]==i){
            for(int j=i;j<=maxn;j+=i){
                euler[j]=euler[j]/i*(i-1);
            }
        }
        for(int j=1;j*i<=maxn;j++){
            f[i*j]+=j*i*euler[i]/2*i;
        }
    }
    for(int i=2;i<=maxn;i++){
        f[i]+=f[i-1];
    }
}

int main()
{
    euler_init();
    int t,n;
    scanf("%d",&t);
    for(int j=1;j<=t;j++){
        scanf("%d",&n);
        LL ans=0;
        cout<<"Case "<<j<<": "<<f[n]<<endl;
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <map>
#include <cmath>
#include <map>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
using namespace std;
#define LL long long
#define maxn 4000005
LL euler[maxn+5];
LL f[maxn+5];
void euler_init(){
    memset(f,0,sizeof(f));
    for(int i=0;i<=maxn;i++) euler[i]=i;
    for(int i=2;i<=maxn;i++){
        if(euler[i]==i){
            for(int j=i;j<=maxn;j+=i){
                euler[j]=euler[j]/i*(i-1);
            }
        }
        for(int j=1;j*i<=maxn;j++){
            f[i*j]+=euler[i]*j;
        }
    }
}

int main()
{
    euler_init();
    int n;
    while(scanf("%d",&n),n){
        LL ans=0;
        for(int i=1;i<=n;i++){
            ans+=f[i];
        }
        printf("%lld\n",ans);
    }
    return 0;
}

技术转移机构如何提高项目转化效率?.docx 科易网基于40亿+科创知识图谱数据库,深度探索AI技术在技术转移、成果转化、技术经纪、知识产权、产业创新、科技招商等垂直领域的多样化应用场景,研究科技创新领域的AI+数智化解决方案,推动科技创新与产业创新智能化发展。 立即下载

相关推荐

Light OJ 1375 LCM Extreme 欧拉函数 (或 莫比乌斯反演 ?)

题目大意: 大意很好理解,就是

Gatevin的专栏 3468

1375 - LCM Extreme

思路: S(n)=sigama(LCM(n, i)) (1     =n*sigama(i/Gcd(n,i))     =n*sigama(d|n{sigama(i|Gcd(n,i)=d)}/d) 而sigama(i){Gcd(n,i)=d}=d*sigama(i|Gcd(n/d,i)=1) 所以上式=n*sigama(d|n,sigama(i|Gcd(n/d,i)=

yerongsc的专栏 702

LightOJ 1375 LCM Extreme(最小公倍数和)

题目链接:http://lightoj.com/volume_showproblem.php?problem=1375 题意:给出n。求allPairLcm函数的返回值。 思路:   其中,这一步 的原因是,每个小于x的数中与x互质的数字之和等于phi[x]/2*x,因为它们是成对出现的,且每对之和为x,比如x=12,那么与x互质的数字为1,5,7,11,其中1+11=5...

weixin_34334744的博客 521

UVALive 5964 LCM Extreme(数论 欧拉函数)

/* 2 题目大意:求lcm(1,2)+lcm(1,3)+lcm(2,3)+....+lcm(1,n)+....+lcm(n-2,n)+lcm(n-1,n) 3 设sum(n)为sum(lcm(i,j))(1<=i<j<=n)之间最小公倍数的和,f(n)为sum(i*n/gcd(i,n))(1<=i<n) 4 那么sum(n)=sum(n-1)+f(n)。可以用线性欧拉筛选+递推来做。 *

Step by step 1009

CSU1803 2016 同余

Description  给出正整数 n 和 m,统计满足以下条件的正整数对 (a,b) 的数量: 1. 1≤a≤n,1≤b≤m; 2. a×b 是 2016 的倍数。 Input 输入包含不超过 30 组数据。 每组数据包含两个整数 n,m (1≤n,m≤109). Output 对于每组数据,输出一个整数表示满足条件的

Megumin的博客 1580

LightOJ1236 Pairs Forming LCM 素数筛法+分解质因数

Description Find the result of the following code: long long pairsFormLCM( int n ) {     long long res = 0;     for( int i = 1; i  n; i++ )         for( int j = i; j  n; j++ )

Megumin的博客 1146

POJ2992 Divisors 组合数,分解质因数

Description Your task in this problem is to determine the number of divisors of Cnk. Just for fun -- or do you need any special reason for such a useful computation? Input The input consists of

Megumin的博客 1033

CodeForces711E ZS and The Birthday Paradox 费马小定理求逆元

ZS the Coder has recently found an interesting concept called the Birthday Paradox. It states that given a random set of 23 people, there is around 50% chance that some two of them share the same birt

Megumin的博客 837

UVa11582 巨大的斐波那契数 循环节计算+快速幂

The i ’th Fibonacci number f(i) is recursively defined in the following way: • f(0) = 0 and f(1) = 1 • f(i + 2) = f(i + 1) + f(i) for every i ≥ 0 Your task is to compute some values of this sequenc

Megumin的博客 829

LightOJ1067 Combinations Lucas定理裸题

Description Given n different objects, you want to take k of them. How many ways to can do it? For example, say there are 4 items; you want to take 2 of them. So, you can do it 6 ways. Take 1, 2 T

Megumin的博客 810

UVa1635 Irrelevant Elements

Young cryptoanalyst Georgie is investigating different schemes of generating random integer numbers ranging from 0 to m - 1. He thinks that standard random number generators are not good enough, so he

Megumin的博客 664

LightOJ1045 Digits of Factorial 求n的阶乘在k进制下的位数

Description Factorial of an integer is defined by the following function f(0) = 1 f(n) = f(n - 1) * n, if(n > 0) So, factorial of 5 is 120. But in different bases, the factorial may be different.

Megumin的博客 654

LightOJ1007 Mathematically Hard 欧拉函数+前缀和

Description Mathematically some problems look hard. But with the help of the computer, some problems can be easily solvable. In this problem, you will be given two integers a and b. You have to fi

Megumin的博客 641

LightOJ1278 Sum of Consecutive Integers 素数筛法+数学分析

Description Given an integer N, you have to find the number of ways you can express N as sum of consecutive integers. You have to use at least two integers. For example, N = 15 has three solutions,

Megumin的博客 637

Hdu5776 sum 抽屉原理+同余定理

Problem Description Given a sequence, you're asked whether there exists a consecutive subsequence whose sum is divisible by m. output YES, otherwise output NO   Input The first line of the input

Megumin的博客 590

Hdu2588 GCD 欧拉函数

Problem Description The greatest common divisor GCD(a,b) of two positive integers a and b,sometimes written (a,b),is the largest divisor common to a and b,For example,(1,2)=1,(12,18)=6.  (a,b) can

Megumin的博客 587

LightOJ1014 Ifter Party

Description I have an Ifter party at the 5th day of Ramadan for the contestants. For this reason I have invited C contestants and arranged P piaju's (some kind of food, specially made for Ifter). Eac

Megumin的博客 573

UVa12716 GCD XOR

Description Given an integer N, nd how many pairs (A; B) are there such that: gcd(A; B) = A xor B where 1 Here gcd(A; B) means the greatest common divisor of the numbers A and B. And A xor B is

Megumin的博客 540
上一篇: POJ2398 Toy Storage 判断点和线的关系+二分+计数
Megumin
博客等级 码龄10年 3粉丝 89原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值