博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
数论 - 筛法暴力打表 --- hdu : 12876 Quite Good Numbers
阅读量:6148 次
发布时间:2019-06-21

本文共 2659 字,大约阅读时间需要 8 分钟。

 

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 22 100 01000 9999 30 0 0
Sample Output
Test 1: 11Test 2: 2Test 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
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define MAX 1000005#define LL long longusing 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<
<

  

转载于:https://www.cnblogs.com/crazyacking/p/3901754.html

你可能感兴趣的文章
MySQL 文件导入出错
查看>>
HDU2502 月之数(解法三)
查看>>
栈的压入、弹出序列 (剑指offer)
查看>>
java相关
查看>>
由一个异常开始思考springmvc参数解析
查看>>
layer弹出层不居中解决方案,layer提示不屏幕居中解决方法,layer弹窗不居中解决方案...
查看>>
获取本机外网ip和内网ip
查看>>
sql优化
查看>>
hammer.js移动端手势库
查看>>
hightcharts 3d 堆积图下钻
查看>>
201621123018《Java程序设计》第1周学习报告
查看>>
ArrayList 源码分析
查看>>
前端工程化(Gulp、Webpack)-webpack
查看>>
JS函数式编程 数组部分风格 ES6版
查看>>
PHP 7 修改了什么呢 -- 2
查看>>
大数据与云计算学习:数据分析(二)
查看>>
JavaScript设计模式系列一:工厂模式
查看>>
Spring声明式事务管理之一:五大属性分析
查看>>
世界上最简单的无等待算法(getAndIncrement)
查看>>
unity如何实现一个固定宽度的orthagraphic相机
查看>>