HNU2014暑假赛七
来源:互联网 发布:pi数据库 api 编辑:程序博客网 时间:2024/04/29 20:24
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 0Sample Output
Test 1: 11Test 2: 2Test 3: 6Problem Source
HNU Contest
当时做这道题的时候,想的是一个一去求出每个数的差距badness,结果一个TLE,各种素数筛选优化都不行,最后看了别人的思路,才知道,可以这样去筛选。
#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<string>
#include<stack>
#include<queue>
#include<climits>
#include<map>
#define MAXP(x,y) (((x)>(y))?(x):(y))
#define MINP(x,y) (((x)<(y))?(x):(y))
const int MAX=0xfffffff;
using namespace std;
const int mx=1000010;
int a[1000010];
void init( )
{
for(int i=2;i<mx;i++)
a[i]=1;
for(int i=2;i<=1000000;i++)
for(int j=2;i*j<=1000000;j++)
a[i*j]+=i;
}
int main( )
{
//freopen("1.txt","r",stdin);
init();
int s,t,b;
int kase=0;
while(cin>>s>>t>>b&&(s||t||b))
{
int cnt=0;
for(int i=s;i<=t;i++)
if(abs(i-a[i])<=b)
cnt++;
printf("Test %d: %d\n",++kase,cnt);
}
return 0;
}
- HNU2014暑假赛七
- HNU暑假赛七B
- 暑假总结(七)
- 暑假七月底一周总结
- 2017七林暑假集训day3
- 2017暑假七林集训day4
- 2017暑假七林集训day8
- 2017暑假七林集训day9
- 2017暑假七林集训day10
- 2017暑假七林集训day11
- 2017暑假七林集训day12
- 2017暑假七林集训day13
- 2017暑假七林集训day14
- 2017暑假七林集训day15
- 2017暑假七林集训day16
- 2017暑假七林集训day17
- 2017暑假七林集训day18
- 2017暑假七林集训day21
- EBS Form个性化的工作原理
- UVA 1397 - The Teacher's Side of Math(高斯消元)
- OTT盒子市场起量正当时 12家主控厂商争夺3000万市场
- Android控件之ListView
- 饕餮盛宴之设计模式
- HNU2014暑假赛七
- 程序员面试问题(二)
- Android中的Handler总结
- ——继承与多态
- hdu 1394 Mininum Inversion Number(线段树版)
- 如何启用Oracle EBS Form监控
- win7家庭组尚未准备就绪
- android学习--DatePickerDialog和TimePickerDialog的使用
- OC语言 block 和 代理模式