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 设在二进制中从 ...
随机推荐
- python_glob模块的使用
glob是Python自己带的一个文件操作相关模块,用它可以查找符合自己目的的文件,就类似于Windows下的文件搜索,支持通配符操作,*,?,[]这三个通配符,*代表0个或多个字符,?代表一个字符, ...
- 完全免费,再也不用担心转pdf文件乱来乱去的问题了
完全免费,再也不用担心转pdf文件乱来乱去的问题了. 源代码:https://github.com/xlgwr/WpsToPdf.git 第三方插件Bye Bye... 功能说明 主要引用Wps金山办 ...
- 巨丑vue
<template> <div> <div class="demo-type" align="right" style=" ...
- 获取当前页面的webview ID
代码: A页面 <script type="text/javascript"> var ws = null; mui.plusReady(function(){ ws ...
- PHP学习之PHP代码的优化
if代码块的优化 if(1===$orderState){ $status='success'; }else{ $status='error'; } return $status; 简 ...
- 性能测试 | Linux系统top命令中的io使用率,很多人都误解了它的具体含义
body{ text-align:left; width:80%; margin:10px 100px; } 最近在做连续数据流的缓冲系统,C语言代码实现后,粗略测试了下,功能上应该没有问题.那么,接 ...
- jq批量与表单赋值
function loadData(obj) { var key, value, tagName, type, arr; for (x in obj) { key = x; value = obj[x ...
- 操作 SQL语句之数据操作语言(DML)详解
一.插入数据(INSERT) MariaDB [(none)]> help insertName: 'INSERT'Description:Syntax:INSERT [LOW_PRIORITY ...
- swoole详解
1.swoole结构图 2.swoole流程图 3.详细流程图 3.1.Master:处理核心事件驱动(主进程)3.2.Reactor: 处理TCP连接,收发数据的线程.Swoole的主线程在Acce ...
- vue-cli2.x版本安装vue-cli建项目
全局安装vue-cli 命令行输入: vue-cli版本在3以下 npm install --global vue-cli 安装vue-cli后,可以查看一下是否安装成功vue --version, ...