题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=4473

题目意思
定义f(x) = 满足(a * b)|x的有序对(a,b)的个数。
然后输入一个n,求f(1) + f(2) + ... + f(n)
废话不多说,此题的关键在于:
把原题的条件(a * b)|x 转化为 a * b * y = x
然后就很好计算了,就是,输入一个n,计算有多少有序对(a, b ,y)满足a*b*y<=n
不妨设a<=b<=y
则,a<=n^(1/3) , b<=sqrt(n/a)
那么
对于三个数字都相同的情况,只计算一次: i i i
对于三个数字中有两个相同的情况,计算3次: i i j, i j i, j i i
对于均不相同的情况,计算6次: a b y ,a y b ,b a y ,b y a, y a b ,y b a

超时代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <iterator>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <cctype>
using namespace std; typedef __int64 LL;
const int N=400005;
const LL II=1000000007;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0); LL pow3(LL n)
{
LL p=(LL)pow(n,1.0/3);
while(p*p*p<=n) p++;
while(p*p*p>n) p--;
return p;
} LL pow2(LL n)
{
LL p=(LL)pow(n,1.0/2);
while(p*p<=n) p++;
while(p*p>n) p--;
return p;
} int main()
{
LL n;
int ca=0;
while(~scanf("%I64d",&n))
{
LL m,t,ans=0,i,j,k;
m=pow3(n);t=pow2(n);
for(i=1;i<=m;i++)
for(j=i;j<=t;j++)
for(k=j;k<=n;k++)
{
if(i*j*k>n) continue;
if(i==j&&j==k)
ans++;
else if(i<j&&j<k)
ans+=6;
else
ans+=3;
}
printf("Case %d: %I64d\n",++ca,ans);
}
return 0;
}

AC代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <iterator>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <cctype>
using namespace std; typedef __int64 LL;
const int N=400005;
const LL II=1000000007;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0); LL pow3(LL n)
{
LL p=(LL)pow(n,1.0/3);
while(p*p*p<=n) p++;
while(p*p*p>n) p--;
return p;
} LL pow2(LL n)
{
LL p=(LL)pow(n,1.0/2);
while(p*p<=n) p++;
while(p*p>n) p--;
return p;
} int main()
{
LL n;
int ca=0;
while(~scanf("%I64d",&n))
{
LL m,ans=0,i,j;
m=pow3(n);
ans+=m;//第一种,三个相等的情况
for(i=1;i<=m;i++)
{
LL t=n/i;
LL k=pow2(t);
ans+=(t/i+k-i*2)*3;//第二种,前两个相等-后面的比前面的大,或则后两个相同比前面的大
for(j=i+1;j<=k;j++)
ans+=(t/j-j)*6;//第三种,都不相等从小到大
}
printf("Case %d: %I64d\n",++ca,ans);
}
return 0;
}

HUD 4473 Exam的更多相关文章

  1. HDU 4473 Exam 枚举

    原题转化为求a*b*c <=n中选出两个数组成有序对<a,b>的选法数. 令a<=b<=c.... 分情况讨论: (1)全部相等,即a = b = c. 选法有n^(1/ ...

  2. hdu 4473 Exam 数学

    思路: 将条件转化为满足abc<=n的abc的数目. 1.3个数相等时,为 A; 2.有2个数相等时,为 B; 3.都不相等时,为 C. 则结果为A+3*B+6*C. 代码如下: #includ ...

  3. Linux学习之Exam系统发布

    配置时间:2015年11月27日 配置人:撰写人:微冷的雨   Happy 01.Linux安装图 欢迎页面 桌面 02.Linux命令之文件目录操作 给北大青鸟五道口校区创建三个机房(L4,L5,L ...

  4. 如何用Unity GUI制作HUD

    若知其所以然,自然知其然. HUD是指平视显示器,就是套在脸上,和你的眼睛固定在一起,HUD的意思就是界面咯,一般我们说HUD特指把3D空间中的界面的某些信息(比如血条,伤害之类)的贴在界面上,对应3 ...

  5. xamarin UWP平台下 HUD 自定义弹窗

    在我的上一篇博客中我写了一个在xamarin的UWP平台下的自定义弹窗控件.在上篇文章中介绍了一种弹窗的写法,但在实际应用中发现了该方法的不足: 1.当弹窗出现后,我们拖动整个窗口大小的时候,弹窗的窗 ...

  6. xamarin UWP设置HUD加载功能

    使用xamarin开发的时候经常用到加载HUD功能,就是我们常见的一个加载中的动作,Android 下使用 AndHUD , iOS 下使用 BTProgressHUD, 这两个在在 NuGet 上都 ...

  7. OSG中的HUD

    OSG中的HUD 所谓HUD节点,说白了就是无论三维场景中的内容怎么改变,它都能在屏幕上固定位置显示的节点. 实现要点: 关闭光照,不受场景光照影响,所有内容以同一亮度显示 关闭深度测试 调整渲染顺序 ...

  8. CREATE A ENERGY / HEALTH BAR HUD

    Now then, let's get started. 1. Open the Play scene which you had created in the previous post. If y ...

  9. iOS之UI--指示器HUD的创建和设置

    指示器的创建和设置 渐变动画 描述: 使用label就能制作指示器,原理:就是让label以动画的形式慢慢显示和消失 最好是半透明的 指示器有时候也被称为:HUD,遮盖,蒙版 思路步骤: 1.先在st ...

随机推荐

  1. zookeeper参考

        ZooKeeper是一个分布式的,开放源码的分布式应用程序协调服务,它是一个为分布式应用提供一致性服务的软件,提供的功能包括:配置维护.名字服务.分布式同步.组服务等.     我需要运行几个 ...

  2. 微信网页授权java实现

    功能:主要用于在用户通过手机端微信访问第三方H5页面时获取用户的身份信息(openId,昵称,头像,所在地等..)可用来实现微信登录.微信账号绑定.用户身份鉴权等功能.     开发前的准备: 1.需 ...

  3. jQuery.fn和jQuery.prototype jquery.extend() jquery.fn.extend()区别介绍

    这里的 jQuery , jQuery.fn , jQuery,fn,init ,jQuery,prototype 都代表什么. 来看下jQuery的源码是怎么样定义的: (function( win ...

  4. linux下修改.bash_profile立即生效的三种方法

    1 . .bash_profile 2 source .bash_profile 3 exec bash --login

  5. openstack 升级设计要求的指导原则

    不知道其他软件有没有类似的指导原则. Theory of Upgrade Grenade works under the following theory of upgrade. New code s ...

  6. Sequence operation(线段树区间多种操作)

    Sequence operation Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  7. Objective-C基础笔记(2)@property和@synthesize

    先贴出使用@property和@synthesize实现的上一篇中的代码,再解释这两个keyword的使用方法和含义,代码例如以下: Person.h文件 #import <Foundation ...

  8. WPF基础——继承

    1)  可以定义继承自其他类的类,关系是“父类/子类”.子类继承父类的成员(不严谨) 2)  定义语法“class子类:父类”,不指定父类则父类为Object,.Net中所有类都直接或者间接继承自Ob ...

  9. jQuery为多个元素绑定相同的事件

    方式一: // 假设$("#div1", "#divN")有多个对象$("#div1", "#divN").each(f ...

  10. 开发移动端web的一些知识

    由于智能机的普及,越来越多网页支持移动端了,那么如何解决适配移动端呢 在这总结一下自己的学习笔记 viewport:虚拟的容器,仅在移动设备有效 <meta name="viewpor ...