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. Spring2:bean的使用

    前言 Spring最基础的功能就是一个bean工厂,所以本文讲解的是Spring生成bean的种种方法及细节,Spring配置文件的名字是bean.xml,定义几个类: 一个Person类: publ ...

  2. java算法(一)

    最近在看各种经典算法,自己写起来: 一.判断素数问题: 知识点:素数即为质数,一个数n若不是质数则一定在2-n/2之间内有因数. package JingDian; public class sush ...

  3. 手把手教你用python打造网易公开课视频下载软件4-图形化界面

    上一篇讲解完函数:def getdownLoadInfo (url): 传入公开课的url地址,就可以提取课程的信息,这一篇讲解一下如何编写图像化界面.大概思考一下图像化界面需要的内容: (1)一个标 ...

  4. 泛型实现中没有正确lock引用类型的一个隐藏bug分析

    最近看到这篇文章dotNetDR_的回复,让我想起一个真实发生的案例,下面就简单说说这个关于lock引用类型的一个不容易发现的隐藏缺陷. 某类库中的代码,封装了很简单的一个通用类,用于线程安全地执行某 ...

  5. mysql: error while loading shared libraries: libmysqlclient.so.16

    [root@host_41 mysql]# mysqlmysql: error while loading shared libraries: libmysqlclient.so.16: cannot ...

  6. easy-ui JOB 及 小记录

    $:获取  $.ajax({             type: "POST" ,             url: "" ,             cont ...

  7. sonne_game网站开发02spring+mybatis框架搭建

    从最开始搭框架谈起,而且,我不仅仅会讲how,还会努力讲why.因为对于web开发,由于有太多好的框架.组件.工具,使得how往往不是那么深刻,背后的why更值得专研.如果有初学者关注我这个系列,也一 ...

  8. 理解nginx的配置

    Nginx配置文件主要分成四部分:main(全局设置).server(主机设置).upstream(上游服务器设置,主要为反向代理.负载均衡相关配置)和 location(URL匹配特定位置后的设置) ...

  9. Angularjs学习---ubuntu12.04中karma安装配置中常见的问题总结

    karma启动时出现了很多问题: 1.安装karma前提条件 安装karma首先要安装nodejs,npm然后才可以安装karma.nodejs,npm的安装过程可以参考文章:Angularjs学习- ...

  10. Atitit 图像处理之理解卷积attilax总结

    Atitit 图像处理之理解卷积attilax总结 卷积的运算可以分为反转.平移,相乘,求和.        在图像处理中,图像是一个大矩阵,卷积模板是一个小矩阵.按照上述过程,就是先把小矩阵反转,然 ...