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. JS让任意图片垂直水平居中且页面不滚动

    说一下以前遇到的一个问题: 假设有一张小图,要实现点击查看大图的功能,而这个图的宽高可能会超过浏览器的宽高,这时候我们通过JS来改变图片的宽高,从而实现图片在浏览器居中显示且不滚屏. 方法如下: 首先 ...

  2. JS获取当前时间及时间戳相互转换

    1.获取当前时间的 时间戳 Date.parse(new Date()) 结果:1486347562000 2.获取当前 时间 new Date() 结果:Mon Feb 06 2017 10:19: ...

  3. POJ3159:Candies(差分约束)

    Candies Time Limit: 1500MS   Memory Limit: 131072K Total Submissions: 39666   Accepted: 11168 题目链接:h ...

  4. Vue项目中引入外部文件(css、js、less)

    例子中css文件采用bootstrap.css,js文件采用jQuery,less文件用less.less(自定义文件) 步骤一:安装webpack cnpm install webpack -g 步 ...

  5. fs.watch 爬坑

    上星期用 fs.watch 和 readline.createInterface 对pm2的合并日志做了监控,根据指定的错误信息重启服务 发现不管是手动vim编辑日志,还是等待日志自动输出. fs.w ...

  6. [BZOJ1982][POJ1740][Spoj 2021]Moving Pebbles|解题报告

    这道题的题意BZ和POJ上的都不大清楚... 大概就是给出n堆石子,以及初始每堆石子的个数 两个玩家交替操作,每个操作可以任意在一堆中取任意多的石子 然后再从这堆里拿若干个石子放到某个当前还存在的堆里 ...

  7. laravel 获得各个根文件夹路径的方法及路由的一些使用

    各个根文件夹路径的方法 APP目录: app_path(); config目录: config_path(); public目录: public_path(); storage目录: storage_ ...

  8. C++类学习

    一.C++类的定义     C++中使用关键字 class 来定义类, 其基本形式如下:class 类名{ public: //行为或属性  protected: //行为或属性 private: / ...

  9. ubuntu下中文输入法安装

    个人认为ubantu下fcitx比sogo好用 安装fcitx首先到ubantu软件中心下载fcitx两个软件,一个是配置软件,一个是输入法软件 到system setting中language su ...

  10. IE67下去掉input边框

    除了 border:none;之外 需要 border-color:#fff; overflow:hidden;