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. 设计模式之美:State(状态)

    索引 意图 结构 参与者 适用性 效果 相关模式 实现 实现方式(一):由 ConcreteState 指定它的后继 State. 意图 允许一个对象在其内部状态改变时改变它的行为.对象看起来似乎修改 ...

  2. httpclient瓶颈

    问题现象: 1.系统异常,应用拒绝访问. 2.web容器线程爆满 问题分析: 1.数据库正常 2.日志信息没有异常 问题思考: 1.应用访问量突破顶峰. 2.应用在某处存在瓶颈 发现问题: 需要了解线 ...

  3. Wix 安装部署教程(十) --来,用WPF做个漂亮的安装界面

    在上一篇中曾留下两个问题,.Net捆绑安装不触发以及路径选择的问题现在都已经解决,这段时间花的最多的地方还是WPF调样式上面,奈何WPF功力不够,暂时还是没有达到自己想要的效果.另外ViewModel ...

  4. [.net 面向对象编程基础] (6) 基础中的基础——运算符和表达式

    [.net 面向对象编程基础] (6) 基础中的基础——运算符和表达式 说起C#运算符和表达式,小伙伴们肯定以为很简单,其实要用好表达式,不是一件容易的事.一个好的表达式可以让你做事半功倍的效果,比如 ...

  5. C# 关于Try/Catch对系统性能影响的总结

    自从开始考虑代码的运行效率和性能以后,写代码考虑的东西越来越多了,比如什么时候应该加try/catch?加太多的try/catch会不会降低性能?今天就来分享一下对try/catch对性能影响的一些看 ...

  6. 自定义样式的select下拉框深入探索

    第一个版本: 首先实现自定义select下拉框应该具有的功能,我是选择将原来的select隐藏掉,自己在jquery代码中动态写进去<dl><dd><dt>这样的结 ...

  7. 如何在遍历中使用 iterator/reverse_iterator 删除元素

    如何在遍历中使用 iterator/reverse_iterator 删除元素 罗朝辉 (http://www.cnblogs.com/kesalin/) 本文遵循“署名-非商业用途-保持一致”创作公 ...

  8. 如何为编程爱好者设计一款好玩的智能硬件(七)——LCD1602点阵字符型液晶显示模块驱动封装(上)

    当前进展: 一.我的构想:如何为编程爱好者设计一款好玩的智能硬件(一)——即插即用.积木化.功能重组的智能硬件模块构想 二.别人家的孩子:如何为编程爱好者设计一款好玩的智能硬件(二)——别人是如何设计 ...

  9. C++虚函数表

    大家知道虚函数是通过一张虚函数表来实现的.在这个表中,主要是一个类的虚函数的地址表,这张表解决了继承.覆盖的问题,其内容真是反应实际的函数.这样,在有虚函数的类的实例中,这个表分配在了这个实例的内存中 ...

  10. svn import-纳入版本控制

    转svn import-纳入版本控制 import: 将未纳入版本控制的文件或目录树提交到版本库.用法: import [PATH] URL 递归地提交 PATH 的副本至 URL.  如果省略 PA ...