SPOJ DIVSUM Divisor Summation

求一个数的所有真因子的和的方法 方法一:利用唯一分解定理。 任何一个大于一的自然数N,如果N不为质数,那么N可以唯一分解成有限个质数的乘积。 N=pow(p1,a1)*pow(p2,a2)*pow(p3,a3)*....*pow(pn,an); 全体正因数和: sum=(1+pow(p1,1)+pow(p... 阅读详情

Divisor Summation 

Description

Given a natural number n (1 <= n <= 500000), please output the summation of all its proper divisors.

Definition: A proper divisor of a natural number is the divisor that is strictly less than the number.

e.g. number 20 has 5 proper divisors: 1, 2, 4, 5, 10, and the divisor summation is: 1 + 2 + 4 + 5 + 10 = 22.

 

Input

An integer stating the number of test cases (equal to about 200000), and that many lines follow, each containing one integer between 1 and 500000 inclusive.

Output

One integer each line: the divisor summation of the integer given respectively.

Example

Sample Input:
3
2
10
20

Sample Output:
1
8
22

Warning: large Input/Output data, be careful with certain languages



解题思路:

计算每个因子的贡献。

AC代码:

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

typedef long long ll;
const int N = 500005;
ll dp[N];

void init(){
    for(int i = 1; i < N; ++i){
        for(int j = 2*i; j < N; j+=i){
            dp[j] += i;
        }
    }
}

int main(){
    int n;
    memset(dp, 0, sizeof(dp));
    init();
    int T;
    scanf("%d", &T);
    while(T--){
        scanf("%d",&n);
        printf("%lld\n", dp[n]);
    }
    return 0;
}


TCGA数据集介绍及数据下载指南(新手友好篇) 目录一、TCGA数据集介绍1.1 数据集介绍1.2 File介绍1.2.1 Data Category(数据类别)1.2.2 Data Type(数据类型)1.2.3 Experimental Strategy(实验策略)1.2.4 Workflow Type(工作流类型)1.2.5 Data Format(数据格式)1.2.6 Platform(平台)1.2.7 Access1.3 Cases介绍1.3.1 Case ID(案例编号)1.3.2 Primary Site(主要站点)1.3.3 Progra 阅读详情

相关推荐

计算机三级考试嵌入式系统重点精简汇总

第一章 嵌入式系统概论 1.1.1嵌入式系统 (1)特点:(1)专用性;(2)隐蔽性;(3)资源受限;(4)高可靠性;(5)实时性;(6)软件固化。 (2)应用:(1)冰箱、洗衣机、电饭煲、空调、摄影机、DVD播放器等;(2)数控机床、飞机、汽车、电梯、X光机、血压计等;(3)电话机、传真机、打印机、pos机、GPS导航仪、路由器等。 1.1.2嵌入式系统组成与分类 (1)逻辑组成:硬件和软件,分为处理器、存储器、I|0设备与I|O接口,数据总线; (2)处理器:分为主处理器(CPU)和协处

chemkrik的博客 1万+

NVIDIA DRIVE SDK学习(二)——NvMedia

可以通过使用NvSciBuf API通过NvMedia Tensor属性分配NvSciBuf来创建NvMedia张量。由于NvSciBuf API有助于NvMedia和NVIDIA®CUDA®之间的数据共享,这使得分配的张量可以在NvSciBuf API允许的情况下重复使用。它支持图像聚合操作。NvSciSync组件使得NvMedia组件可以与其他组件保持同步,比如CUDA组件、基于NvSciSync的组件等。立体视差模式:在这种模式下,该模块通过左图像和右图像来产生立体视差,从而进行物体深度测量。

weixin_39592381的博客 3052

Divisor Summation约数之和

Divisor Summation Description Give a natural number n (1 <= n <= 500000), please tell the summation of all its proper divisors. Definition: A proper divisor of a natural number is the divisor that

wwk0125的专栏 1075

Verilog实战:手把手教你实现四路组相联Cache(附完整代码解析)

本文提供了一份详细的Verilog实战指南,手把手教你实现一个四路组相联Cache。内容涵盖从设计规格、核心存储阵列、LRU替换策略到状态机设计的完整流程,并附有代码解析与优化技巧,旨在帮助硬件设计者掌握Cache控制器的RTL实现与调试方法。

pp12345的博客 524

conda环境的复制、备份操作

请确保将 source_env 替换为你要复制的现有环境的名称,并将 target_env 替换为你要创建的新环境的名称。要备份一个Conda虚拟环境,你需要将环境的配置信息和依赖包列表保存起来,以便在需要的时候能够重新创建相同的环境。要将现有的 conda 环境复制为其他环境,可以使用 conda create 命令并克隆已存在的环境。

Dollhan的博客 3776

SPOJ DIVSUM Divisor Summation

DIVSUM - Divisor Summation #number-theory Given a natural number n (1 Definition: A proper divisor of a natural number is the divisor that is strictly less than the number. e.g. number

MADE_Y 851

西门子1500 PLC与巴鲁夫RFID实战:从硬件接线到数据读写的完整流程

本文详细介绍了西门子S7-1500 PLC与巴鲁夫RFID系统集成的完整实战流程。内容涵盖从硬件选型、接线、PROFINET网络配置,到在TIA Portal中安装GSD文件、组态设备、分配地址,再到使用标准功能块(如FB31)进行程序架构设计、实现数据读写以及错误诊断。文章重点分享了硬件连接要点、软件配置步骤、数据块管理技巧以及调试中常见问题的解决方案,为工业自动化工程师实施RFID项目提供了清晰的指导。

weixin_29161785的博客 394

Divisor Summation(与求约数个数类似)

Sum of Divisors Time Limit: 1000MS Memory Limit: 32768K 64bit IO Format: %lld & %llu [Submit]   [Go Back]   [Status] Description For an integer n, define f(n) to be the sum of its proper

wwk0125的专栏 662

Ansys Lumerical 启动时出现 Error: Could not connect to Ansys license server specified at 1055@ 的一种解决办法

考虑到 2020 版的时候是直接在全局变量里指定具体地址,但是 2024 版本是写成 1055@localhost ,并且之后在站里搜相关 Ansys 的问题都指向 1055 端口被占用,虽然问题不一样,但是本着死马当活马医,就按照。我最近在跑超透镜结构,听说2024版本现在有GPU加速可以用,就把Lumerical从2020升到2024版本,结果发现一开头的破解办法完全不一样了。一开始安装的时候以为2020没有删干净,导致2024版的安装一直锁着目标地址,解决办法参考。的办法来操作,在关闭了。

qq_51404184的博客 5790

宝马项目化流程标准(BMW ABC flyer requirement)

宝马项目化流程标准(BMW ABC flyer requirement)

于大博 7275

SPOJ DIVSUM - Divisor Summation

题目链接:http://www.spoj.com/problems/DIVSUM/ 题目大意:问N的除自己外所有因数的和。例如250 是 218(1 + 2 + 5 + 10 + 25+ 50 +125). 解题思路:采用类似埃氏筛的方法。 不知道暴力能不能过。。。 代码: 1 int n; 2 ll a[maxn]; 3 4 void solve(){ ...

EricJeffrey的博客 186

基于深度学习的工业零件缺陷检测系统

工业零件缺陷检测系统摘要 本文介绍了一个基于深度学习的工业零件缺陷检测系统解决方案。该系统采用Faster R-CNN目标检测算法,结合PyTorch框架和OpenCV图像处理库,实现了对工业零件表面缺陷(如裂纹、划痕、凹坑等)的自动检测与定位。系统包含完整的开发流程:从数据采集与标注、数据增强预处理、模型构建与训练,到最终的评估与部署。相比传统机器视觉方法,该深度学习方案具有更强的特征表示能力和环境适应性,能够有效提升工业质检的准确率和效率。文章详细阐述了系统架构设计、实现细节和优化策略,并提供了完整的代

huanghm88的专栏 292

F-Divisor Summation|约数枚举

题目链接:http://www.spoj.com/problems/DIVSUM/en/ 水题一道,这里不详细说明。 以下是AC代码: /* name:Rollchuchy type: */ #include #include #include #include #include #define MAX_N 500005 using namespace std; int num[500005

社畜のブログ 529

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

SPOJ 74. Divisor Summation 分解数字的因子

本题有两个难点: 1 大量的数据输入,没处理好就超时 - 这里使用buffer解决 2 因子分解的算法 a)暴力法超时 b)使用sieve(筛子),不过其中的算法逻辑也挺不容易搞对的。 数值N因子分解逻辑: 1 保存所有可以sqrt(N)范围内的质素 2 找到可以被N除尽的质素d, 然后用d去除N,使用deg变量,保存度,即有多少个d可以被N除尽 3 用d去乘所有已经找到的因子

靖空间 1607

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

ZOJ 2095 Divisor Summation (求因子和)

Divisor Summation Time Limit: 5 Seconds      Memory Limit: 32768 KB Give a natural number n (1 Definition: A proper divisor of a natural number is the divisor that is strictly less than the nu

滴水穿石,慢慢积累,总会有成果 716

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

SPOJ:[DIVCNT3]Counting Divisors

题目大意:求1~N的每个数因子数的立方和。 题解:由于N过大,我们不能直接通过线性筛求解。我们可以采用洲阁筛。 洲阁筛的式子可以写成: 对于F(1~√n),可以直接线性筛求解。 对于,我们进行以下DP: g[i][j]为1~j中,与前i个质数互质的数的F值之和。 dp过程中,有 如果p[i]>j,则g[i][j]=F(1); 如果p[...

weixin_30569033的博客 139

筛法的应用

                                   筛法的应用一.用筛法求指定区间上的所有素数,并统计素数的个数.   筛法: 这是一种效率较高的算法.   求素数的筛法是公元前3世纪的厄拉多塞(Eratosthenes)提出来的:对于一个大整数X,只要知道不超过   sqrt(X)的所有素数,划去所有p的倍数2p,3p,...剩下的整数就是不超过X的全部素数.   应用筛法求素

fisher_jiang的专栏 2952

Divisor Summation_

Divisor Summation Problem Description Give a natural number n (1 <= n <= 500000), please tell the summation of all its proper divisors. Definition: A proper divisor of a natural number is the di...

weixin_30649859的博客 206

Divisor Summation

2095 Divisor Summation<br />曾经acm2007-05-01 23:15:24阅读7评论1  字号:大中小 订阅<br />Time limit: 5 Seconds   Memory limit: 32768K   <br />Total Submit: 4504   Accepted Submit: 862   <br />Give a natural number n (1 <= n <= 500000), please tell the summation of all i

a11a2233445566的专栏 970

1185Divisor Summation

注意:直接用循环找它的因数容易时间超限!!#include&lt;stdio.h&gt;int  main(){    int n,i,sum,m,j;    scanf("%d",&amp;n);    for(i=0;i&lt;n;i++)    {        sum=0;        scanf("%d",&amp;m);        if(m!=1)        {       ...

shufuyouqian的博客 276

ZOJ -2095 Divisor Summation

Divisor Summation Time Limit: 5 Seconds Memory Limit: 32768 KB Give a natural number n (1 <= n <= 500000), please tell the summation of all its proper divisors. Definition: A proper divis...

名字太长容易被发现并打死 555

【简单】Divisor Summation

描述 Give a natural number n (1 <= n <= 500000), please tell the summation of all its proper divisors. Definition: A proper divisor of a natural number is the divisor that is strictly less than th...

Skynamer的博客 421

快速求欧拉函数

hdu2824 快速求欧拉函数 标签: integeroutputeachlessinput百度 2012-04-02 00:50 3499人阅读 评论(0) 收藏 举报  分类: 数论(7)  版权声明:本文为博主原创文章,未经博主允许不得转载。 目录(?)[+] 欧拉函数的定义可以自己百度 phi(n)=n*(1

silence401的博客 1465

LightOJ 1213-Fantasy of a Summation【快速幂】

If you think codes, eat codes then sometimes you may get stressed. In your dreams you may see huge codes, as I have seen once. Here is the code I saw in my dream. #include &lt;stdio.h&gt;int cases, c...

独钓门前月 474
上一篇: POJ 1730 Perfect Pth Powers(素数筛选法)
下一篇: hdu 3586 Information Disturbing(树形dp)
yphacker
博客等级 码龄12年 199粉丝 540原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值