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 设在二进制中从 ...
随机推荐
- SRS之SrsHls::on_video详解
1. SrsHls::on_video /* * mux the video packets to ts. * @param shared_video, directly ptr, copy it i ...
- 脚本:将git项目下载到本地并启动
大致思路:从git上clone源代码到本地:使用mvn package将源代码达成war/jar包:将打好的包放到tomcatpath/webapps/下:到tomcatpath/bin/下执行res ...
- Qt之CMake和MinGW编译OpenCV
这里编译的是最新版OpenCV3.4.3,编译过程比较曲折,大部分编译错误都可以查得到解决方法,也遇到了Google无果的错误,好在最后还是解决了,特此记录. 编译环境 win10-64bit Qt5 ...
- git 命令简洁手册
1.从当前目录初始化 git init 2.对文件进行跟踪 或 将已跟踪的文件放到暂缓区 或 把有冲突的文件标记为已解决状态 git add <file> 3.从现有仓库克隆 git c ...
- LC 794. Valid Tic-Tac-Toe State
A Tic-Tac-Toe board is given as a string array board. Return True if and only if it is possible to r ...
- 重画GoogleClusterTrace数据
由于项目计划书写作需要,重画了Qi Zhang, Mohamed Faten Zhani, Raouf Boutaba, Joseph L. Hellerstein, Dynamic Heteroge ...
- [Mysql]一对多关系是如何发挥作用的?
一个孩子只有一个妈妈,而一个妈妈可以有多个孩子,这是典型的一对多的关系,这里采用navicat图形化界面建立二者的关系. 第一步:创建mother表,如下图: 第二步:创建children表,在ch ...
- an extra named object property
Grunt supports the ability to split each task configuration into several separate configurations all ...
- 各种集合key,value能否为null
转: 各种集合key,value能否为null 2019年03月12日 13:22:58 mingwulipo 阅读数 238 HashMap key,value都可以为null static f ...
- PLSQL连接本地oracle或远程oracle数据库,实现随意切换
转: PLSQL连接本地oracle或远程oracle数据库,实现随意切换 置顶 2018年01月12日 19:36:45 前方一片光明 阅读数 43542 版权声明:本文为博主原创文章,未经博主 ...