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 设在二进制中从 ...
随机推荐
- C# 父类代码动态转换子类
百度上搜索C# 如何父类运行时转换成子类,没有得到相应答案,突然想起C# 有dynamic类型试试看结果成功了... 以后编写代码类似这样的代码 就可以删减掉了 if (en.type == EMap ...
- Zookeeper原理 二
Zookeeper到底是什么!? 学一个东西,不搞明白他是什么东西,哪还有心情学啊!! 首先,Zookeeper是Apache的一个java项目,属于Hadoop系统,扮演管理员的角色. 然后看到官网 ...
- Maximum GCD(UVA 11827)
Problem:Given the N integers, you have to find the maximum GCD (greatest common divisor) of every po ...
- vueApp打包
本地打包测试 http-server是一个基于node.js的简单的,零配置的命令行http服务器.安装:npm install http-server -g使用:http-server [path] ...
- 【记录】springboot项目的maven的pom.xml文件第一行报错 Unknown Error
原因 : maven的插件版本的问题,造成与IDE的不兼容 解决办法 :在pom中加上 <maven-jar-plugin.version>3.1.1</maven-jar-plug ...
- 简易总结react-hook三大基础
react-hook的最重要的三大基础 import { useEffect, useState, useContext } from 'react' 1.每一个简单的一句话总结 useEffect ...
- JVM | JVM的核心技术
说到JVM,很多工作多年的老铁,可能就有点发憷了,因为搬砖多年,一直使用java这个工具,对于JVM没有了解过,有句话面试造航母,上班拧螺丝,要啥自行车啊,知道如何搬砖就可以了,为啥要懂这么多,如果你 ...
- centos 下启动 rabbitmq 报错的解决
安装 rabbitmq 后进行了一些配置,然后启动服务: service rabbitmq-server start 无法启动.通过 journalctl -xe 查看日志后,有如下日志: ... - ...
- 摘抄java基础
1.Java中Static的相关用法总结?(静态方法:静态变量:静态代码块) public static void main(String args[])执行的关键,在于有static.有了stati ...
- react-native-swiper设定高度的方法(设置rn轮播图所占高度)
效果图: 直接上解决方案: 1.在Swiper标签外套一层View <View style={styles.container}> <Swiper style={styles.wra ...