链接:https://www.nowcoder.com/acm/contest/158/A

考虑每个数对答案的贡献,所以答案就是$\sum_{i=1}^{n}{\lfloor\frac{n}{i}\rfloor}$

整除分块搞起来

代码:

 #include<iostream>
#include<cstdio>
#include<cstring>
#define ll long long
using namespace std;
int q;
ll n,ans;
int main()
{
scanf("%d",&q);
while(q--)
{
scanf("%lld",&n);
ans=;
for(ll l=,r;l<=n;l=r+) {r=n/(n/l);ans+=(r-l+)*(n/l);}
printf("%lld\n",ans);
}
return ;
}

[nowcoder]因数个数和的更多相关文章

  1. q次询问,每次给一个x,问1到x的因数个数的和。

    q次询问,每次给一个x,问1到x的因数个数的和. #include<cmath> #include<cstdio> #include<cstring> usingn ...

  2. 积性函数&线性筛&欧拉函数&莫比乌斯函数&因数个数&约数个数和

    只会搬运YL巨巨的博客 积性函数 定义 积性函数:对于任意互质的整数a和b有性质f(ab)=f(a)f(b)的数论函数. 完全积性函数:对于任意整数a和b有性质f(ab)=f(a)f(b)的数论函数 ...

  3. 牛客练习赛25 A 因数个数和(数论分块)

    题意: q次询问,每次给一个x,问1到x的因数个数的和. 1<=q<=10 ,1<= x<=10^9 1s 思路: 对1~n中的每个数i,i作为i,2i,3i,...的约数,一 ...

  4. 【牛客练习赛 25】A 因数个数和

    题目地址:https://www.nowcoder.com/acm/contest/158/A 参考博客:https://blog.csdn.net/zzcblogs/article/details/ ...

  5. 如何求数字n的因数个数及因数和

    我们有可能在某些数学题中会求到某个数的因数和,那我们怎么求呢? 因为我们知道任意一个合数都可以由两个或多个质数相乘得到,那么我们就先分解质因数吧 例:我们随便去一个数吧,嗯,就108了,好算... 我 ...

  6. LightOJ-1138 Trailing Zeroes (III) 唯一分解定理 算n!的某个因数个数

    题目链接:https://cn.vjudge.net/problem/ 题意 找一个最小的正整数n 使得n!有a个零 思路 就是有几个因数10呗 考虑到10==2*5,也就是说找n!因数5有几个 数据 ...

  7. 【数论】[因数个数]P4167樱花

    题目描述 求不定方程 \(\frac {1}{x} + \frac{1}{y} = \frac{1}{n!}\)的正整数解的个数 \(n \leq 100^6\) Solution 化简得 \(x * ...

  8. Pollard_rho定理 大数的因数个数 这个板子超级快

    https://nanti.jisuanke.com/t/A1413 AC代码 #include <cstdio> #include <cstring> #include &l ...

  9. 牛客训练赛25-A-因数个数

    题目链接https://www.nowcoder.com/acm/contest/158/A 无语...这题很迷啊,原谅我的菜,刚开始想用预处理欧拉筛和前缀和,可是这题太血崩了,这样一样要遍历,1-e ...

随机推荐

  1. UIImagePickerController在UIPopoverController中 旋屏问题

    1弧度=180/π度1度=π/180弧度今天遇到了 一个问题.UIImagePickerController在UIPopoverController中 旋屏问题. 在查找了许多资料后方知,此乃iOS系 ...

  2. Pycharm 2017 12月最新激活码

    激活的办法:这个必须的联网才可以使用(每次打开PyCharm都需要电脑联网才可以正常使用),要是没网的话,就不能激活使用啦,大家注意哈. http://idea.iteblog.com/key.php ...

  3. [LintCode] 有效回文串

    class Solution { public: /** * @param s A string * @return Whether the string is a valid palindrome ...

  4. [POJ] Brackets Sequence

    This problem can be solved elegantly using dynamic programming. We maintain two arrays: cnt[i][j] -- ...

  5. [Algorithms] Sorting Algorithms (Insertion Sort, Bubble Sort, Merge Sort and Quicksort)

    Recently I systematicall review some sorting algorithms, including insertion sort, bubble sort, merg ...

  6. grunt的简单应用

    grunt是干什么的呢,一句话:自动化.对于需要反复重复的任务,例如压缩(minification).编译.单元测试.linting等,自动化工具可以减轻你的劳动,简化你的工作.当你在 Gruntfi ...

  7. MVC异步消息推送机制

    在MVC里面,有异步控制器,可以实现模拟消息推送机制功能 1.控制器要继承至AsyncController,如 public class RealTimeController : AsyncContr ...

  8. 【Python之路】第十七篇--Ajax全套

    概述 1.传统的Web应用 一个简单操作需要重新加载全局数据 2.AJAX AJAX,Asynchronous JavaScript and XML (异步的JavaScript和XML),一种创建交 ...

  9. 浅谈 Python 的 with 语句(转)

    add by zhj: 上下文管理器是对try-except-finally的再封装而已,只能算是优化代码这一级别的feature 原文:http://www.ibm.com/developerwor ...

  10. 用Android NDK编译FFmpeg

    附(2018-01-06):     有一个将x264及lame等库集成进去了且基于android的ffmpeg的编译方法,地址参见:       https://github.com/writing ...