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

Input
11
1
4
5
10
100
99
16
64
49
50
48
Output
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的更多相关文章

  1. 【Gym - 100923I】Por Costel and the Pairs(思维题)

    Por Costel and the Pairs Descriptions 有T组测试样例 有n个男的,n个女的,第i个人都有为当前一个大小为i的懒惰值,当一男一女懒惰值的乘积<=n他们就就可以 ...

  2. 【动态规划】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 ...

  3. 【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 ...

  4. 【找规律】Gym - 100923L - Por Costel and the Semipalindromes

    semipal.in / semipal.out Por Costel the pig, our programmer in-training, has recently returned from ...

  5. 【分块打表】Gym - 100923K - Por Costel and the Firecracker

    semipal.in / semipal.out Por Costel the pig, our programmer in-training, has recently returned from ...

  6. 【并查集】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 ...

  7. 【带权并查集】Gym - 100923H - Por Costel and the Match

    裸题. 看之前的模版讲解吧,这里不再赘述了. #include<cstdio> #include<cstring> using namespace std; int fa[10 ...

  8. 【Gym - 100923A】Por Costel and Azerah(思维水题)

    Por Costel and Azerah Descriptions 给你n个数 问你,有多少个子序列 的和是偶数 Example Input 233 10 124 2 Output 33 题目链接 ...

  9. UVa 1451 (数形结合 单调栈) Average

    题意: 给出一个01串,选一个长度至少为L的连续子串,使得串中数字的平均值最大. 分析: 能把这道题想到用数形结合,用斜率表示平均值,我觉得这个想法太“天马行空”了 首先预处理子串的前缀和sum,如果 ...

随机推荐

  1. AWS nat monitor and route switch script

    This script will monitor another NAT instance and take over its routes if communication with the oth ...

  2. VC++中编译C出错:error C2143: syntax error : missing ';' before 'type'

    转摘自:http://preceo.blog.51cto.com/6225017/1130931 近来写程序时发现了一个问题,用 VC 编译 C语言是 总是提示一个错误:error C2143: sy ...

  3. CMOS与BIOS

    BIOS与CMOS的区别 : 1. 所谓BIOS,实际上就是微机的基本输入输出系统(Basic Input-Output System),其内容集成在微机主板上的一个ROM芯片上,主要保存着有关微机系 ...

  4. 【SPOJ-QTREE】树链剖分

    树链剖分学习 https://blog.csdn.net/u013368721/article/details/39734871 https://www.cnblogs.com/George1994/ ...

  5. [bzoj1486][HNOI2009]最小圈——分数规划+spfa+负环

    题目 传送门 题解 这个题是一个经典的分数规划问题. 把题目形式化地表示,就是 \[Minimize\ \lambda = \frac{\sum W_{i, i+1}}{k}\] 整理一下,就是 \[ ...

  6. mongoDB的简单使用

    1.客户端连接: ./mongo 2.数据库 一个mongodb中可以建立多个数据库. MongoDB的默认数据库为"db",该数据库存储在data目录中. MongoDB的单个实 ...

  7. time,random,os,sys,序列化模块

    一.time模块 表示时间的三种方式 在Python中,通常有这三种方式来表示时间:时间戳.元组(struct_time).格式化的时间字符串: (1)时间戳(timestamp) :通常来说,时间戳 ...

  8. 详解SHOW PROCESSLIST显示哪些线程正在运行列出的状态

    SHOW PROCESSLIST显示哪些线程正在运行.您也可以使用mysqladmin processlist语句得到此信息.如果您有SUPER权限,您可以看到所有线程.否则,您只能看到您自己的线程( ...

  9. ubuntu16.04搭建个人简易DLP

    前言 最近一朋友让我帮忙搭建一台服务器,用做公司的服务器,但是该服务器需要满足一些安全要求,于是乎就有了下面的解决过程^_^ 需求 期望普通用户和管理员都能ssh登陆服务器,但禁止scp或者其他方式下 ...

  10. rtp/rtsp over http的学习

    要做rtp/rtsp over http, 我对http也有点了解, 以前也做过rtp/rtsp over tcp/udp传输264视频流, 但刚开始还是没有一点思路,想着把http和rtp等联系到一 ...