Quite Good Numbers
Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:65536KB
Total submit users: 77, Accepted users: 57
Problem 12876 : No special judgement
Problem description

A "perfect" number is an integer that is equal to the sum of its divisors (where 1 is considered a divisor). For example, 6 is perfect because its divisors are 1, 2, and 3, and 1 + 2 + 3 is 6. Similarly, 28 is perfect because it equals 1 + 2 + 4 + 7 + 14.
A "quite good" number is an integer whose
"badness" ? the absolute value of the difference between the sum of its divisors
and the number itself ? is not greater than a specified value. For example, if
the allowable badness is set at 2, there are 11 "quite good" numbers less than
100: 2, 3, 4, 6, 8, 10, 16, 20, 28, 32, and 64. But if the allowable badness is
set at 0 (corresponding to the "perfect" numbers) there are only 2: 6 and
28.
Your task is to write a program to count how many quite good numbers (of
a specified maximum badness) fall in a specified range.

Input

Input will consist of specifications for a series of tests. Information for
each test is a single line containing 3 integers with a single space between
items:
• start (2 <= start < 1000000) specifies the first number to
test
• stop (start <= stop < 1000000) specifies the last number to
test
• badness (0 <= badness < 1000) specifies the maximum allowable
badness
A line containing 3 zeros terminates the input.

Output

Output should consist of one line for each test comprising the test number
(formatted as shown) followed by a single space and the number of values in the
test range with badness not greater than the allowable
value.

Sample Input
2 100 2
2 100 0
1000 9999 3
0 0 0
Sample Output
Test 1: 11
Test 2: 2
Test 3: 6
Problem Source
HNU Contest 

Mean:

让你求从sta到end这个区间中有多少个数满足:abs(sum-i)<=bad。其中sum是i所有的因子之和,bad是给定的值,代表误差。

analyse:

由于数字很大,必须打表,我们将10^6次方内i的因子之和求出来。

从筛法求素数得到的启发,方法很巧妙,具体看代码。

Time complexity:O(n)

Source code:

//Memory   Time
// 4988K 40MS
// by : Snarl_jsb
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<iomanip>
#include<string>
#include<climits>
#include<cmath>
#define MAX 1000005
#define LL long long
using namespace std;
int sta,stop,bad,ans,kase=1;
int sum[MAX];
void make_table()
{
for(int i=2;i<=MAX;i++)
{
sum[i]++;
for(int j=2;i*j<=MAX;j++) sum[i*j]+=i;
}
}
int main()
{
make_table();
while(scanf("%d %d %d",&sta,&stop,&bad),ans=0,sta+stop+bad)
{
printf("Test %d: ",kase++);
for(int i=sta;i<=stop;i++)
{
if(abs(sum[i]-i)<=bad) ans++;
}
cout<<ans<<endl;
}
return 0;
}

  

数论 - 筛法暴力打表 --- hdu : 12876 Quite Good Numbers的更多相关文章

  1. hdu 1431 素数回文(暴力打表,埃托色尼筛法)

    这题开始想时,感觉给的范围5 <= a < b <= 100,000,000太大,开数组肯定爆内存,而且100000000也不敢循环,不超时你打我,反正我是不敢循环. 这题肯定得打表 ...

  2. HDU 1012 u Calculate e【暴力打表,水】

    u Calculate e Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  3. HDU 1216 Assistance Required(暴力打表)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1216 Assistance Required Time Limit: 2000/1000 MS (Ja ...

  4. 暴力打表之hdu 2089

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2089 有两种方法: 1.数位DP算法 2.暴力打表——真是个好法子!!! 接下来是注意点: 1.一般这 ...

  5. HDU 5179 beautiful number (数位dp / 暴力打表 / dfs)

    beautiful number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  6. ACM/ICPC 之 暴力打表(求解欧拉回路)-编码(POJ1780)

    ///找到一个数字序列包含所有n位数(连续)一次且仅一次 ///暴力打表 ///Time:141Ms Memory:2260K #include<iostream> #include< ...

  7. XTU OJ 1210 Happy Number (暴力+打表)

    Problem Description Recently, Mr. Xie learn the concept of happy number. A happy number is a number ...

  8. 【ZOJ】3785 What day is that day? ——浅谈KMP在ACM竞赛中的暴力打表找规律中的应用

    转载请声明出处:http://www.cnblogs.com/kevince/p/3887827.html    ——By Kevince 首先声明一下,这里的规律指的是循环,即找到最小循环周期. 这 ...

  9. Codeforces 914 C 数位DP+暴力打表+思维

    题意 给出一个二进制数\(n\),每次操作可以将一个整数\(x\)简化为\(x\)的二进制表示中\(1\)的个数,如果一个数简化为\(1\)所需的最小次数为\(k\),将这个数叫做特殊的数, 问从\( ...

随机推荐

  1. 团队项目——站立会议DAY10

    第十次站立会议记录: 参会人员:张靖颜,钟灵毓秀,何玥,赵莹,王梓萱 项目进展: 1.张靖颜:进一步完善程序代码,提出扩展性的建议,增加程序的功能. 2.钟灵毓秀:修改已完成代码出现的bug,完善代码 ...

  2. Java集合List模拟“洗牌”操作

    Collection工具类为操作List集合提供了几个有用的方法: reverse().shuffle().sort().swap().rotate(). 小例子: 使用shuffle(),方法模拟洗 ...

  3. 翻译-Salt与Ansible全方位比较

    原文链接:http://jensrantil.github.io/salt-vs-ansible.html 作者: Jens Rantil 之前某些时候我需要评估配置管理系统.结合从他人得到的意见,我 ...

  4. Atitit 判断判断一张图片是否包含另一张小图片

    Atitit 判断判断一张图片是否包含另一张小图片 1. keyword1 2.  模板匹配是在图像中寻找目标的方法之一(切割+图像相似度计算)1 3. 匹配效果2 4. 图片相似度的算法(感知哈希算 ...

  5. iOS 屏幕适配:autoResizing autoLayout和sizeClass

    1. autoResizing autoresizing是苹果早期的ui布局适配的解决办法,iOS6之前完全可以胜任了,因为苹果手机只有3.5寸的屏幕,在加上手机app很少支持横屏,所以iOS开发者基 ...

  6. Socket实现仿QQ聊天(可部署于广域网)附源码(1)-简介

    1.前言 本次实现的这个聊天工具是我去年c#程序设计课程所写的Socket仿QQ聊天,由于当时候没有自己的服务器,只能在机房局域网内进行测试,最近在腾讯云上买了一台云主机(本人学生党,腾讯云有个学生专 ...

  7. 体验WP 8.1 Update1开发不一定要更新VS2013 Update3

    WP 8.1开发者预览版,估计大家也用得很High了,最近,MS推送了Update,主要的东西,不用说,就是最近被说得很火的小娜(Cortana),其实在推Update前几天,还有过一次小更新,当然我 ...

  8. CentOS6.5使用createrepo搭建本地源

    本地搭建本地yum源采用的rpm全部来自CentOS-6.5-bin-DVD1&DVD2; 我的是在虚拟机环境安装,先检查我的操作系统版本: 1 2 3 4 [adam@ultraera ~] ...

  9. hibernate(四)ID生成策略

    一.ID生成策略配置 1.ID生成方式在xml中配置方式: <?xml version="1.0"?> <!DOCTYPE hibernate-mapping P ...

  10. Android实现下滑和上滑事件

    做过开发的对于下滑刷新与上滑加载都一定不陌生,因为我们在很多时候都会使用到,那对对于这个效果如何实现呢?相信难道过很多小伙伴,今天我就带领大家一道通过第三方组件快速完成上述效果的实现,保准每位小伙伴都 ...