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

华为云计算——FusionCompute创建虚拟机 阅读详情

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

华为OD机试真题 新系统2026-04-08 C++ 实现【直捣黄龙】 小王在玩一款叫做直捣黄龙的小游戏,在该游戏中他需要从入口位置进入敌营,绕过哨兵的层层封锁,达到敌军司令部实施斩首行动。 敌军阵营是一个n*n的矩阵,入口在坐标(0,n/2),敌军司令部在坐标(n-1,n/2),每个 哨兵警戒以自己为中心的9宫格,一旦被哨兵发现则行动失败。 阅读详情

相关推荐

如何有效爬取“好大夫”评论数据?技术实现与合规性分析

本文探讨了爬取好大夫在线医生评论数据的技术与合规性问题。分析了好大夫平台评论数据的价值和特点,指出其动态加载和反爬机制的挑战。技术上,推荐使用Selenium模拟浏览器行为获取数据,并提供了分页爬取、代理IP、验证码识别等解决方案。同时强调必须遵守平台的爬虫策略,关注用户协议和隐私保护法规,建议通过官方API或授权方式获取数据。文章还讨论了数据清洗存储方法,并提醒注意数据伦理和最小化抓取原则。本文为医疗数据爬取提供了技术实现和合规性指导的平衡方案。

专注于Python爬虫开发,分享爬虫技巧、项目实战与反爬经验,使用Scrapy、BeautifulSoup等工具,解决数据抓取难题。 1079

LightOJ 1375 - LCM Extreme 莫比乌斯反演或欧拉扩展

题意:给出n [1,3*1e6] 求 并模2^64。 思路:先手写出算式 观察发现可以化成 那么关键在于如何求得i为1~n的lcm(i,n)之和。可以知道lcm(a,b)为ab/gcd(a,b) 变换得(a/gcd) (b/gcd)gcd 由于GCD的性质,可以知道a/gcd 与 b/gcd是互质的两个质数。由此可以想到应用欧拉函数,并且由性质能够证明 nphi(n)/2为小于n所有与n互质数...

weixin_30681121的博客 263

缠论中枢python源码_缠论分笔及中枢主图源码

HV1:=HHVV AND H>=HHV(H,BARSLAST(LLVV));LV1:=LLVV AND L<=LLV(L,BARSLAST(HHVV));DRAWLINE(LV1,LOW,HV1, HIGH,COLORYELLOW);DRAWLINE(HV1,HIGH,LV1, LOW,COLORMAGENTA); ///加入中枢判定//简化版N1:=10;N2:=10;DISP:=...

weixin_39789094的博客 8768

UVALive 5964 LCM Extreme(数学)

题目链接 :http://vjudge.net/problem/viewProblem.action?id=29410 题意 : 求∑lcm(i, j) (其中1 <= i < j <= n) n <= 5 * 10 ^ 6 做contest的时候一开始看到这道题目我想到贾教的线筛那篇论文上好像是讲到过这个的,然后就去翻了...到最后还是不理解怎么做 - -b 思路...

weixin_30611509的博客 163

携程滑块、点选验证码登录识别逆向

本文分析了携程登录系统的风控机制,主要包含三种验证场景:无验证码、滑块验证码和二次图标点选验证码。通过跟踪risk_inspect风控接口,发现验证流程采用标准AES加密,需提交设备指纹等加密信息。当触发验证码时,需额外提交包含轨迹坐标的verify_msg参数及token/rid参数。最终通过风控检测后,需使用一致的指纹参数和验证token完成加密登录。文章强调所有分析仅用于学习,代码实现需确保符合法律规范。

码王吴彦祖的博客 1114

【电容/电感】电路板会“滋滋”的响,我们称它为啸叫

一、啸叫的起源 大部分硬件工程师应该都遇到过,PCBA上电后出现“滋滋滋”的叫声,其声响或大或小,或时有时无,或深沉或刺耳,或变化无常者皆有。该现象我们称为“啸叫”,一般分为电感啸叫和电容啸叫。

云轩阁 6万+

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

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

Gatevin的专栏 3474

基于深度学习的停车位检测系统(UI界面 + YOLOv8/v7/v6/v5代码 + 训练数据集)

传统的停车位检测方法主要依赖于人工或基于简单图像处理的技术,存在检测速度慢、准确率低、环境适应性差等问题。近年来,随着深度学习技术的快速发展,基于目标检测的停车位检测系统已成为研究的热点。本文基于YOLO(You Only Look Once)系列模型(包括YOLOv5、YOLOv6、YOLOv7和YOLOv8),开发了一个完整的停车位检测系统,支持实时检测、结果可视化以及UI交互界面。本文实现了一个基于深度学习的停车位检测系统,采用YOLO模型在实时视频流中进行高效检测。

YOLO 335

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

【WLAN】【基础知识】WIFI那些事儿之信道和频谱(涵盖2.4G、5G、6G,全网最全)

- 从事WIFI相关开发或测试工作,经常要和信道、频宽、频率等打交道,本文仅将平时涉及的2.4G、5G、6G的信道、频宽、频率等做一总结。 - 一图胜万言,本文汇总了工作中经常用到的频谱图,保证全网最全!!! - 本博客地址,https://blog.csdn.net/qxhgd,欢迎各位关注,转发请注明出处。

一介草民,只为生活。 1万+

RK3588 部署 YOLO26 目标检测:从环境搭建到 NPU 推理

采集图像(500+ 张,覆盖不同光照和角度)→ 筛选(删除模糊、无目标的图像)→ LabelImg 标注(选择 YOLO 格式)→ 划分 train:val:test = 7:2:1labelImg├── train/├── val/nc: 3类别顺序必须与 LabelImg 标注时一致。YOLO26 在 RK3588 上的部署流程是 PC 端训练 → ONNX 导出(opset=11)→ RKNN 转换(INT8 量化)→ 板端推理。

LXY_LOVE36的博客 432

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 1010

【雕爷学编程】Arduino动手做(111)---震动提醒模块

37款传感器与执行器的提法,在网络上广泛流传,其实Arduino能够兼容的传感器模块肯定是不止这37种的。鉴于本人手头积累了一些传感器和执行器模块,依照实践出真知(一定要动手做)的理念,以学习和交流为目的,这里准备逐一动手尝试系列实验,不管成功(程序走通)与否,都会记录下来---小小的进步或是搞不掂的问题,希望能够抛砖引玉。

雕爷学编程 1903

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

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

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的博客 1585

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

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的博客 1147

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

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的博客 1035

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的博客 839

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的博客 832

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的博客 815

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的博客 665

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的博客 656

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的博客 645

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的博客 640

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的博客 591

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

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址