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. ENode 1.0 - 整体架构介绍

    前言 今天是个开心的日子,又是周末,可以安心轻松的写写文章了.经过了大概3年的DDD理论积累,以及去年年初的第一个版本的event sourcing框架的开发以及项目实践经验,再通过今年上半年利用业余 ...

  2. 千万用户级别应用系统背后的SOA组件化容器

    背景 在<我们的应用系统是如何支撑千万级别用户的>随笔中已经从“宏观”角度去介绍了整个应用系统的布局.组件化是整个系统由头到尾都始终坚持的一个设计原则,其中“SOA组件化容器”也是我们应用 ...

  3. 《CLR.via.C#第三版》第一部分读书笔记(一)

    最近开始仔细研读<CLR.via.C#第三版>这本书.读pdf文档确实很累.建议有条件的朋友还是买书看吧. 我的笔记用来记录我对这本书的理解,简化下逻辑,对每个部分我觉得是要点的进行归纳总 ...

  4. 【译】AS3利用CPU缓存

    利用CPU缓存   计算机有随机存取存储器RAM(译注:即我们常说的内存),但有更快形式的存储器.如果你希望你的应用程序的快速运行,你需要知道这些其他的存储器.今天的文章中讨论了它们,并给出了两个AS ...

  5. python property

    python property 在2.6版本中,添加了一种新的类成员函数的访问方式--property. 原型 class property([fget[, fset[, fdel[, doc]]]] ...

  6. 我心中的核心组件(可插拔的AOP)~调度组件quartz.net

    回到目录 quartz.net是一个任务调度组件,它可以灵活的设置你的调试方式,按时间,按日期,按周期都可以很容易的实现,quartz不仅可以用在web中,而且还可以部署在winform,winser ...

  7. 在ubuntu上安装nodejs[开启实时web时代]

    作为一名菜鸟,竟然在centos桌面上连输入命令行的地方都找不到,是在是对不起开山祖师,最后苍天不负苦心人,在ubuntu上找见了 [安装过程参考了http://cnodejs.org/topic/4 ...

  8. Mysql 事件(定时任务)

    mysql 创建任务(事件) 1.检查数据库事件是否开启,如果 event_scheduler 等于 NO表示开启 SELECT @@event_scheduler; SHOW VARIABLES L ...

  9. DBCC SHOW_STATISTICS 查看统计信息

    使用DBCC Show_Statistics 能够查看 表或Indexed view上的统计信息.Query optimizer使用统计信息进行estimate,生成高质量的qeury plan.统计 ...

  10. Object.create

    var emptyObject = Object.create(null); var emptyObject = Object.create(null); var emptyObject = {}; ...