【数形结合】Gym - 100923I - Por Costel and the Pairs
perechi3.in / perechi3.out
We don't know how Por Costel the pig arrived at FMI's dance party. All we know is that he did.
The dance floor is hot because Por Costel broke the air conditioner. On the dance floor, the boys and girls are clumsy. There are boys at the party. The
-th one has clumsiness level
. There ale also
girls at the party. The
-th girl has clumsiness level
as well. Por Costel finds that a pair of a boy and a girl can dance only if the product of their clumsiness levels is at most
, i.e. girl clumsiness level * boy clumsiness level
. Por Costel thinks that a sack of oats with a slice of leek could make a better dancing pair than the people at this party. Nonetheless, he would like to find out how many pairs (boy, girl) can dance. The input will contain the number
representing the number of tests. The next
lines will contain the number
.
Input
The input file perechi3.in will contain the number representing the number of tests. The next
lines will each contain a single integer
.
Output
The output file perechi3.out should have lines. Line
should hold the answer for the
-th test.
Example
11
1
4
5
10
100
99
16
64
49
50
48
1
8
10
27
482
473
50
280
201
207
198
让你求n/1+n/2+...+n/n,除法都是整除。
显然就是xy=n这个双曲线的一支与坐标轴形成的区域内,整点的个数,不包含坐标轴上的点,但包含双曲线上的点。
画一条y=x的直线,将这个区域分成两部分,只需要统计一半的区域即可。
细节自己手推一下就好。
复杂度O(sqrt(n))。
#include<cstdio>
#include<cmath>
using namespace std;
typedef long long ll;
int T;
ll n;
int main()
{
//freopen("i.in","r",stdin);
freopen("perechi3.in","r",stdin);
freopen("perechi3.out","w",stdout);
scanf("%d",&T);
for(;T;--T)
{
ll ans=0;
int cnt=0;
scanf("%I64d",&n);
if(n==1ll)
{
puts("1");
continue;
}
ll x=(ll)sqrt((double)n+0.5);
ll t=0;
for(ll i=1;i<=x;++i)
if(i*i<=n)
++t;
else
break;
if(x*x==n)
--x;
for(ll i=x;i>0;--i)
ans+=((n/i)-i);
printf("%I64d\n",(ans<<1)+t);
}
return 0;
}
【数形结合】Gym - 100923I - Por Costel and the Pairs的更多相关文章
- 【Gym - 100923I】Por Costel and the Pairs(思维题)
Por Costel and the Pairs Descriptions 有T组测试样例 有n个男的,n个女的,第i个人都有为当前一个大小为i的懒惰值,当一男一女懒惰值的乘积<=n他们就就可以 ...
- 【动态规划】Gym - 100923A - Por Costel and Azerah
azerah.in / azerah.out Por Costel the Pig has received a royal invitation to the palace of the Egg-E ...
- 【Heap-dijkstra】Gym - 100923B - Por Costel and the Algorithm
algoritm.in / algoritm.out Even though he isn't a student of computer science, Por Costel the pig ha ...
- 【找规律】Gym - 100923L - Por Costel and the Semipalindromes
semipal.in / semipal.out Por Costel the pig, our programmer in-training, has recently returned from ...
- 【分块打表】Gym - 100923K - Por Costel and the Firecracker
semipal.in / semipal.out Por Costel the pig, our programmer in-training, has recently returned from ...
- 【并查集】Gym - 100923H - Por Costel and the Match
meciul.in / meciul.out Oberyn Martell and Gregor Clegane are dueling in a trial by combat. The fight ...
- 【带权并查集】Gym - 100923H - Por Costel and the Match
裸题. 看之前的模版讲解吧,这里不再赘述了. #include<cstdio> #include<cstring> using namespace std; int fa[10 ...
- 【Gym - 100923A】Por Costel and Azerah(思维水题)
Por Costel and Azerah Descriptions 给你n个数 问你,有多少个子序列 的和是偶数 Example Input 233 10 124 2 Output 33 题目链接 ...
- UVa 1451 (数形结合 单调栈) Average
题意: 给出一个01串,选一个长度至少为L的连续子串,使得串中数字的平均值最大. 分析: 能把这道题想到用数形结合,用斜率表示平均值,我觉得这个想法太“天马行空”了 首先预处理子串的前缀和sum,如果 ...
随机推荐
- 如何优化JQuery each()函数的性能
如果对jQuery这东西只停留在用的层面,而不知其具体实现的话,真的很容易用出问题来.这也是为什么近期我一直不怎么推崇用jQuery,这框架的API设定就有误导人们走上歧途之嫌. 01 $.fn.be ...
- 近期对于windows服务的理解
1.APP.config的作用 在开发环境下时,根目录下的APP.config里面会填写一些参数之类的.当生成之后,这些参数将会被自动生成在*.exe文件目录中.如图: 其中,.exe文件为Win ...
- The xor-longest Path [Trie]
The xo-longest Path 题目描述 给定一棵\(n≤100 000\)个点的带权树,求树上最长的异或和路径. 输入 多组数据.每组数据第一行一个整数n(\(1≤n≤100 00\),接下 ...
- lnmp重置mysql数据库root密码
第一种方法:用军哥的一键修改LNMP环境下MYSQL数据库密码脚本 一键脚本肯定是非常方便.具体执行以下命令: wget http://soft.vpser.net/lnmp/ext/reset_my ...
- ES6(ECMAScript2015) 基础知识 浅析
1.块级作用域(let) { let fruit = “apple”; } console.log(fruit) 会报错,因为{ }大括号包含的区域为块级作用域,let在其中申明的变量只能在该块中生效 ...
- 排序(bzoj 4552)
Description 在2016年,佳媛姐姐喜欢上了数字序列.因而他经常研究关于序列的一些奇奇怪怪的问题,现在他在研究一个难题 ,需要你来帮助他.这个难题是这样子的:给出一个1到n的全排列,现在对这 ...
- JVM 性能排查--汇总
参考:http://blog.sina.com.cn/s/blog_61d758500102wnus.html
- UVa11988 Broken Keyboard (a.k.a. Beiju Text)
题目复制太麻烦了,甩个链接 http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=18693 直接模拟光标操作时间复杂度较高,所以用链 ...
- IPsec传输模式下ESP报文的装包和拆包过程
原创文章,拒绝转载 装包过程 总体流程图 过程描述 在原IP报文中找到TCP报文部分,在其后添加相应的ESP trailer信息. ESP trailer 包含三部分:Padding,Pad leng ...
- 【FIRST USE】第一次用git把代码上传到github
第一次使用某个东西总是充满了伤痛,我第一次用sed的时候,毁掉了我的所有源代码,第一次用git的时候一直提示不正确,后来解决了问题,便记录下来. 首先说明我的环境,我用的是虚拟机,上面运行的64位的c ...