筛法求素数变式

Quite Good Numbers
Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:65536KB
Total submit users: 73, Accepted users: 52
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 

给你一个区间和一个数num,要你求区间内满足x-(x的因子和)的绝对值小于num的值的个数.

#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 1000010
#define LL long long
using namespace std;
int sta,en,bad;
int a[MAX];
void make_table()
{
    for(int i=0;i<=MAX;i++)
        a[i]=1;
    for(int i=2;i<=1000000;i++)
    {
        for(int j=2;j*i<=1000000;j++)
        {
            a[j*i]+=i;
        }
    }
}
int main()
{
    make_table();
    int kase=1;
    while(scanf("%d %d %d",&sta,&en,&bad),sta+en+bad)
    {
        int cnt=0;
        for(int i=sta;i<=en;i++)
        {
            if(abs(i-a[i])<=bad)
                cnt++;
        }
        printf("Test %d: %d\n",kase++,cnt);
    }
    return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值