SPOJ - NDIV n-divisors (约数个数问题)

We all know about prime numbers, prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself.

We can Classify the numbers by its number of divisors, as n-divisors-numbers, for example number 1 is 1-divisor number, number 4 is 3-divisors-number... etc.

Note: All prime numbers are 2-divisors numbers.

Example:
8 is a 4-divisors-number [1, 2, 4, 8].

Input

Three integers a, b, n.

Output

Print single line the number of n-divisors numbers between a and b inclusive.

Example

Input:
1 7 2

Output:
4

Constraints

1 <= a, b <=10^9
0 <= b - a <= 10^4
1 <= n <= 100




求一个区间中的约数个数为n的数目,因为数字比较大,但是一个数的因子可以只枚举sqrt(n)便可以知道另一半,因为区间比较小,可以将这个区间中的数打表记录




#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;
const int N = 1010;
typedef long long LL;
int s[100000];



int main()
{
    int a, b, n;
    scanf("%d %d %d", &a, &b, &n);
    memset(s,0,sizeof(a));
    int k=sqrt(b);
    for(int i=1;i<=k;i++)
    {
        for(int j=a/i;j<=b/i+1;j++)
        {
            int h=i*j;
            if(h>=a&&h<=b)
            {
                if(j<=k) s[h-a]++;
                else s[h-a]+=2;
            }
        }
    }
    int cnt=0;
    for(int i=0;i<=b-a;i++)
    {
        if(s[i]==n) cnt++;
    }
    cout<

你可能感兴趣的:(计算数学)