Number of Containers ZOJ - 3175(数论题)
Problem Description
For two integers m and k, k is said to be a container of m if k is divisible by m. Given 2 positive integers n and m (m < n),
the function f(n, m) is defined to be the number of containers of m which are also no greater than n.
For example, f(5, 1)=4, f(8, 2)=3, f(7, 3)=1, f(5, 4)=0...Let us define another function F(n) by the following equation:

Now given a positive integer n, you are supposed to calculate the value of F( n).
Input
There are multiple test cases. The first line of input contains an integer T(T<=200) indicating
the number of test cases. Then T test cases follow.Each test case contains a positive integer n (0 <n <= 2000000000) in a single line.
Output
For each test case, output the result F(n) in a single line.
Sample Input
1
4
Sample Output
4
题目大意:
求 n/i-1;(0<i<n)的和,,,,由于数据高达20亿●﹏●,所以,暴力就会T!!!
思路:
画图,画出函数图像:y = n/x,以 y = x对称可以用 横坐标表示i 从该点画一条垂直的线
这条线上的所有整数点的个数就是 n/i那么n/1+n/2+n/3+……n/(n-2)+n/(n-1)+n/n(有点像调和级数哦じò ぴé)
可以表示为i*(n/i)=n这条线答案就是这条线与坐标轴围成的面积内的整数点的个数画一条x=y的线与xy=n相交
可以知道面积关于 x=y 对称我们只需求n/1+n/2+n/3+……求到k=sqrt(n)处(1个梯形)
之后乘以2(得到2个梯形的面积 其中有一个正方形的区域是重复的)减去重复的区域k*k个
就可以用这个方法,也可以用来快速求(n/1+n/2+n/3+…+n/n)。
参考代码:
#include<iostream>
#include<cmath>
using namespace std;
#define ll long long
int main()
{
int t;
cin>>t;
while(t--)
{
ll n,sum=;
cin>>n;
int m=sqrt(n);
for(int i=;i<=m;i++)
sum+=n/i;
sum*=;
sum=sum-m*m-n;
cout<<sum<<endl;
}
return ;
}
Number of Containers ZOJ - 3175(数论题)的更多相关文章
- Number of Containers(数学) 分类: 数学 2015-07-07 23:42 1人阅读 评论(0) 收藏
Number of Containers Time Limit: 1 Second Memory Limit: 32768 KB For two integers m and k, k is said ...
- BZOJ 3209: 花神的数论题 [数位DP]
3209: 花神的数论题 题意:求\(1到n\le 10^{15}\)二进制1的个数的乘积,取模1e7+7 二进制最多50位,我们统计每种1的个数的数的个数,快速幂再乘起来就行了 裸数位DP..\(f ...
- FJUT-这还是一道数论题
这还是一道数论题 TimeLimit:4000MS MemoryLimit:128MB 64-bit integer IO format:%lld Special Judge Problem D ...
- 【洛谷】4317:花神的数论题【数位DP】
P4317 花神的数论题 题目背景 众所周知,花神多年来凭借无边的神力狂虐各大 OJ.OI.CF.TC …… 当然也包括 CH 啦. 题目描述 话说花神这天又来讲课了.课后照例有超级难的神题啦…… 我 ...
- 【LG4317】花神的数论题
[LG4317]花神的数论题 题面 洛谷 题解 设\(f_{i,up,tmp,d}\)表示当前在第\(i\)位,是否卡上界,有\(tmp\)个一,目标是几个一的方案数 最后将所有\(d\)固定,套数位 ...
- BZOJ3209 花神的数论题 【组合数学+数位DP+快速幂】*
BZOJ3209 花神的数论题 Description 背景 众所周知,花神多年来凭借无边的神力狂虐各大 OJ.OI.CF.TC …… 当然也包括 CH 啦. 描述 话说花神这天又来讲课了.课后照例有 ...
- [BZOJ3209]花神的数论题 组合数+快速幂
3209: 花神的数论题 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 2498 Solved: 1129[Submit][Status][Disc ...
- 【BZOJ3209】花神的数论题 数位DP
[BZOJ3209]花神的数论题 Description 背景众所周知,花神多年来凭借无边的神力狂虐各大 OJ.OI.CF.TC …… 当然也包括 CH 啦.描述话说花神这天又来讲课了.课后照例有超级 ...
- 【bzoj3209】: 花神的数论题 数论-DP
[bzoj3209]: 花神的数论题 首先二进制数中1的个数最多就是64个 设所有<=n的数里二进制中1的个数为i的有a[i]个 那么答案就是 然后快速幂 求a[i]可以用DP 设在二进制中从 ...
随机推荐
- Appium进阶教程
Monkey的使用 adb shell monkey -p com.lqr.wechat -v 500 > monkey.log adb shell monkey -p com.lqr.wech ...
- 【零基础】搞定LAMP(linux、apache、mysql、php)环境安装图文教程(基于centos7)
一.前言 LAMP即:Linux.Apache.Mysql.Php,也就是在linux系统下运行php网站代码,使用的数据库是mysql.web服务软件是apache.之所以存在LAMP这种说法,倒不 ...
- Redis 4.x RCE 复现学习
攻击场景: 能够访问远程redis的端口(直接访问或者SSRF) 对redis服务器可以访问到的另一台服务器有控制权 实际上就是通过主从特性来 同步传输数据,同时利用模块加载来加载恶意的用来进行命令执 ...
- ndarray的axis问题
始终记不住np中axis是对应到哪个,还没系统地去学习下 先暂记两个常用的结果 1.[:,np.newaxis] 与 [np.newaxis, :] 注:这是ndarray才有的分片方法(np重写了[ ...
- mongodb 的云数据库产品 atlas 的使用
前言:最近发现 mlab 被mongodb 收购以后,不再支持新用户,推荐使用 MongoDB Atlas 第一步:注册或登陆 在MongoDB atlas首页,如果有账号,那就点击登陆.否则点击Ge ...
- 封装带SSH跳板机的MYSQL
一.封装带SSH跳板机的MYSQL 二.配置settting import pymysql from sshtunnel import SSHTunnelForwarder class MyDb(ob ...
- 关于go module
从Go 1.11开始引入module,用于版本管理. 通过使用module,工程目录的位置不用必须放在GOPATH下. 当前版本是1.13,下文中将以Go1.13为例介绍module. 在Go 1.1 ...
- Android:JNA实践(附Demo)
一.JNA和JNI的对比 1.JNI的调用流程 Android应用开发中要实现Java和C,C++层交互时,想必首先想到的是JNI,但是JNI的使用过程十分繁琐,需要自己再封装一层JNI接口进行转 ...
- Jsp +Js + Jquery + EasyUI + Servlet + Lucene,完成分页
package loaderman.fy.action; import java.io.IOException; import java.io.PrintWriter; import java.uti ...
- Android中常见的默认实现类
* Basexxx* Defaultxxx* Simplexxx* Baicxxx