lightoj-1098 - A New Function(因子和)

1098 - A New Function
PDF (English) Statistics Forum
Time Limit: 3 second(s) Memory Limit: 32 MB
We all know that any integer number n is divisible by 1 and n. That is why these two numbers are not the actual divisors of any numbers. The function SOD(n) (sum of divisors) is defined as the summation of all the actual divisors of an integer number n. For example,

SOD(24) = 2+3+4+6+8+12 = 35.

The function CSOD(n) (cumulative SOD) of an integer n, is defined as below:

Given the value of n, your job is to find the value of CSOD(n).

Input
Input starts with an integer T (≤ 1000), denoting the number of test cases.

Each case contains an integer n (0 ≤ n ≤ 2 * 109).

Output
For each case, print the case number and the result. You may assume that each output will fit into a 64 bit signed integer.

Sample Input
Output for Sample Input
3
2
100
200000000
Case 1: 0
Case 2: 3150
Case 3: 12898681201837053

解题思路:

通过一个因子,求出与此因子相对应的其他因子,求和;

例如n=20的时候,当因子为2时,对应的 2(4),3(6),4(8),5(10),6(12),7(14),8(16),9(18),10(10)

当为3时,对应的为2(6),3(9),4(12),5(15),6(18)

此时要计算时要注意避免 2和3时之间有重复的情况。

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

typedef long long ll;
int T;
ll sum,n,p,q,m;

int main(){

    scanf("%d",&T);
    for(int t=1;t<=T;t++){
        sum = 0;
        scanf("%lld",&n);

        m = (ll)sqrt(n);
        for(ll i=2;i<=m;i++){
            sum += i;
            // p,q 变量的增加是为了避免重复情况的产生
            p = i+1;
            q = n/i;
            if(q<q) continue;
            sum += (q-p+1)*i;
            sum += (q-p+1)*(q+p)/2;

        }
        printf("Case %d: %lld\n",t,sum);

    }

    return 0;
}

时间: 2024-08-13 10:10:44

lightoj-1098 - A New Function(因子和)的相关文章

LightOJ - 1098 A New Function

题意:定义SOD(n)=n除去1和自身的所有因数的和,CSOD(n)为ΣSOD(i),1<=i<=n.T (≤ 1000)组数据,求CSOD(n),(0 ≤ n ≤ 2 * 109) 对于不同的数m,m=a*b,a<=b:枚举a,判断不大于n的中有哪些可以写成m=a*b的,把a和b加到答案上.复杂度是O(√n) 如何维护答案呢? 举例子,作为a出现的3有多少次呢?是n/3 * 3吗?并不是.要注意到我们要求a<=b,那么从m=9开始,3才会作为a出现,而3,6中的因数3并不作为a对

LightOJ 1098(均值不等式,整除分块玄学优化)

We all know that any integer number n is divisible by 1 and n. That is why these two numbers are not the actual divisors of any numbers. The function SOD(n) (sum of divisors) is defined as the summation of all the actual divisors of an integer number

LightOJ 13361336 - Sigma Function (找规律 + 唯一分解定理)

http://lightoj.com/volume_showproblem.php?problem=1336 Sigma Function Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Practice LightOJ 1336 Description Sigma function is an interesting function in Number Theor

light_oj 1336 约数和奇偶性

light_oj 1336  约数和奇偶性 D - Sigma Function Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Practice LightOJ 1336 Description Sigma function is an interesting function in Number Theory. It is denoted by the Greek

帮同学做的大一大作业:《我的家乡—郑州》

---恢复内容开始--- 最近在上海上学的一个高中同学让我帮忙,帮她做她们的计算机课程大作业. 由于关系不错我也不好意思拒绝就帮忙做了,因为这个学期刚刚开始接触HTML5和css,所以制作过程中有很多不懂的,而且由于HTML5是选修课,一星期只有一节,所以做这个花费了比较多的时间,这个网站是我制作的第一个网站,比较有纪念意义,所以发在博客上,作为纪念. 通过去做这个作业,我了解到很多课上学不到的东西.因为没有美工,从头到尾,都是我一个人在臆想,刚开始的时候,根本无从下手,我去参考别人做的家乡网站

way.js

1 (function (root, factory) { 2 3 if (typeof define === "function" && define.amd) { 4 define(factory); 5 } else if (typeof exports === "object") { 6 module.exports = factory(); 7 } else { 8 root.way = factory(); 9 } 10 11 }(thi

vxWorks网络设备驱动开发之-muxDevLoad

muxDevLoad是用来加载一个网络设备的,muxDevLoad成功执行后,我们就可以在shell里调用ifconfig命令来察看load的网卡设备了. 先看一下函数的调用流程,最后大概分析一下muxDevLoad的功能. 1726 /****************************************************************************** 1727 * 1728 * usrNetInit - network intialization rou

中国空气质量在线监测分析平台之JS加密、JS混淆处理

中国空气质量在线监测分析平台数据爬取分析 页面分析:确定url.请求方式.请求参数.响应数据 1.访问网站首页:https://www.aqistudy.cn/html/city_detail.html,通过抓包工具分析首页请求并没有获取到页面内的数据信息  2.因此可以确定页面内的数据是动态加载的,通过抓包工具捕获加密的响应对象, 3.加密响应对象是通过post请求携带加密的参数发起(2次). 4.综上分析可以确定,动态请求时在搜索按钮触发时发起的,因此通过火狐firefox浏览器分析页面搜索

通过百度echarts实现数据图表展示功能

现在我们在工作中,在开发中都会或多或少的用到图表统计数据显示给用户.通过图表可以很直观的,直接的将数据呈现出来.这里我就介绍说一下利用百度开源的echarts图表技术实现的具体功能. 1.对于不太理解echarts是个怎样技术的开发者来说,可以到echarts官网进行学习了解,官网有详细的API文档和实例供大家参考学习. 2.以下是我在工作中实现整理出来的实例源码: 公用的支持js文件 echarts.js.echarts.min.js,还有其他的图表需要支持的js文件也可以到官网下载 echa