[nowcoder]因数个数和
链接: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]因数个数和的更多相关文章
- q次询问,每次给一个x,问1到x的因数个数的和。
q次询问,每次给一个x,问1到x的因数个数的和. #include<cmath> #include<cstdio> #include<cstring> usingn ...
- 积性函数&线性筛&欧拉函数&莫比乌斯函数&因数个数&约数个数和
只会搬运YL巨巨的博客 积性函数 定义 积性函数:对于任意互质的整数a和b有性质f(ab)=f(a)f(b)的数论函数. 完全积性函数:对于任意整数a和b有性质f(ab)=f(a)f(b)的数论函数 ...
- 牛客练习赛25 A 因数个数和(数论分块)
题意: q次询问,每次给一个x,问1到x的因数个数的和. 1<=q<=10 ,1<= x<=10^9 1s 思路: 对1~n中的每个数i,i作为i,2i,3i,...的约数,一 ...
- 【牛客练习赛 25】A 因数个数和
题目地址:https://www.nowcoder.com/acm/contest/158/A 参考博客:https://blog.csdn.net/zzcblogs/article/details/ ...
- 如何求数字n的因数个数及因数和
我们有可能在某些数学题中会求到某个数的因数和,那我们怎么求呢? 因为我们知道任意一个合数都可以由两个或多个质数相乘得到,那么我们就先分解质因数吧 例:我们随便去一个数吧,嗯,就108了,好算... 我 ...
- LightOJ-1138 Trailing Zeroes (III) 唯一分解定理 算n!的某个因数个数
题目链接:https://cn.vjudge.net/problem/ 题意 找一个最小的正整数n 使得n!有a个零 思路 就是有几个因数10呗 考虑到10==2*5,也就是说找n!因数5有几个 数据 ...
- 【数论】[因数个数]P4167樱花
题目描述 求不定方程 \(\frac {1}{x} + \frac{1}{y} = \frac{1}{n!}\)的正整数解的个数 \(n \leq 100^6\) Solution 化简得 \(x * ...
- Pollard_rho定理 大数的因数个数 这个板子超级快
https://nanti.jisuanke.com/t/A1413 AC代码 #include <cstdio> #include <cstring> #include &l ...
- 牛客训练赛25-A-因数个数
题目链接https://www.nowcoder.com/acm/contest/158/A 无语...这题很迷啊,原谅我的菜,刚开始想用预处理欧拉筛和前缀和,可是这题太血崩了,这样一样要遍历,1-e ...
随机推荐
- vmware key
VMware vRealize Suite 2017 Enterprise N04CL-09H9H-J89DJ-0KCH6-90N0J VMware vRealize Operations Man ...
- [hihoCoder] 拓扑排序·一
The hints of the problem has given detailed information to implement the topological sorting algorit ...
- 学习使用turtlebot2——调试Hokuyo激光雷达(型号UST-10LX)
目标 在ROS上调试使用Hokuyo激光雷达传感器 配置情况 电脑使用Ubuntu 14.04版本,ROS为 Indigo,激光雷达为Hokuyo(型号UST-10LX,网口型接口) 如果 ...
- PHP错误处理,无法显示验证码。。无法显示首页等莫名其妙的500
use the date.timezone setting or the date_default_timezone_set() 这是由于调用date时,若timezone设置不正确所产生的E_NOT ...
- Lock wait timeout exceeded; try restarting transaction 3千万数据删除
Lock wait timeout exceeded; try restarting transaction 0DELETE FROM sta_addr WHERE date="2018-1 ...
- Spring Mvc4 新特性(一)
前言 Spring Framework的Web层,由spring-web,spring-webmvc,spring-websocket和spring-webmvc-portlet模块组成. 很多人刚学 ...
- python基础之类的静态方法和类方法
一 静态方法 通常情况下,在类中定义的所有函数都是对象的绑定方法,对象再调用绑定方法时会自动将自己作为参数传递给方法的第一个参数.除此之外还有两种常见的方法:静态方法和类方法,二者是为类量身定制的,但 ...
- travelsal all files in a dir using recursion shell
#!/bin/bash function getdir(){ ` do dir_or_file=$"/"$element if [ -d $dir_or_file ] then g ...
- 分别用request和socket给百多发送请求
1.方式1 import socket client = socket.socket() # 百度创建连接: 阻塞 client.connect(('www.baidu.com',80)) # 问百度 ...
- 我的Android进阶之旅------>解决:Failed to create 'build\outputs\apk\watch-debug-unaligned.apks': 拒绝访问。
1. 错误描述 今天用Android Studio进行项目编译的时候,报错如下所示: FAILURE: Build failed with an exception. * What went wron ...