hdu 5750(数论)

Dertouzos

Time Limit: 7000/3500 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 891    Accepted Submission(s): 274

Problem Description

A positive proper divisor is a positive divisor of a number n, excluding n itself. For example, 1, 2, and 3 are positive proper divisors of 6, but 6 itself is not.

Peter has two positive integers n and d. He would like to know the number of integers below n whose maximum positive proper divisor is d.

Input

There are multiple test cases. The first line of input contains an integer T (1≤T≤106), indicating the number of test cases. For each test case:

The first line contains two integers n and d (2≤n,d≤109).

Output

For each test case, output an integer denoting the answer.

Sample Input

9
10 2
10 3
10 4
10 5
10 6
10 7
10 8
10 9
100 13

Sample Output

1
2
1
0
0
0
0
0
4

题意:如果 d 是k除了自身以外最大的因子, 在[2,n)内找有多少个数满足 最大的因子是 k .

题解:昨天想得太简单了,真是naive..我开始的想法是 将 min(d,(n-1)/d) 里面所有的质数算出来,然后天真的以为这就是结果...然后一直WA,忽视了一个很重要的条件,那就是我们的数中d一定是最大的因子,所以如果出现了能够将d整除的质数,那么我们就可以将d分解,从而得到一个更大的 d‘ ,所以说我们选择的质数是不能够将 d 除尽的.

#include<iostream>
#include<cstdio>
#include<cstring>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long LL;
const int N = 100005;
bool p[N];
int prime[N];
int id;
void init()
{
    id = 0;
    for(int i=2; i<N; i++)
    {
        if(!p[i])
        {
            prime[++id] = i;
            for(LL j=(LL)i*i; j<N; j+=i)
            {
                p[j] = true;
            }
        }
    }
}

int main()
{
    init();
    int tcase;
    scanf("%d",&tcase);
    while(tcase--)
    {
        int n,d;
        scanf("%d%d",&n,&d);
        int ans = 0;
        for(int i=1; i<=id; i++)
        {
            if(prime[i]*d>=n) break;
            ans++;
            if(d%prime[i]==0) break;
        }
        printf("%d\n",ans);
    }
    return 0;
}
时间: 2024-08-13 18:14:26

hdu 5750(数论)的相关文章

hdu 4542 数论 + 约数个数相关 腾讯编程马拉松复赛

题目:http://acm.hdu.edu.cn/showproblem.php?pid=4542 小明系列故事--未知剩余系 Time Limit: 500/200 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Submission(s): 889    Accepted Submission(s): 207 Problem Description "今有物不知其数,三三数之有二,五五数之有三,七七数之有

hdu 1124 数论

题意:求n!中末尾连续0的个数  其实就是2*5的个数 30! 中有5 10 15 20 25 30  是5的倍数有6个   6=30/5; 6/5=1; 这个1 为25 5  10 15 20  25  30 35 40 45 50 55 60  65 70 75 80  85 90 95 100      100/5=20; 25                     50                    75                     100       20/5=4

hdu 3641 数论 二分求符合条件的最小值数学杂题

http://acm.hdu.edu.cn/showproblem.php?pid=3641 学到: 1.二分求符合条件的最小值 /*==================================================== 二分查找符合条件的最小值 ======================================================*/ ll solve() { __int64 low = 0, high = INF, mid ; while(low <=

hdu 4961 数论 o(nlogn)

Boring Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 60    Accepted Submission(s): 30 Problem Description Number theory is interesting, while this problem is boring.   Here is the probl

hdu 5750 Dertouzos 素数

Dertouzos Time Limit: 7000/3500 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 1861    Accepted Submission(s): 584 Problem Description A positive proper divisor is a positive divisor of a number n, excluding n its

hdu 1299 数论 分解素因子

题意:求1.1/x+1/y=1/z 给定z 求x,y的个数zsd:1: 要知道这个素数的因子的范围 范围为2--sqrt(n);2: 带入方程得:x = n * n / k + n ; 现在就变成了求x的值.又因为n一定大于k,所以转换成求n * n的分解数: 因为n = p1 ^ e1 * p2 ^ e2 *..........*pn ^ en sum ( n)= ( 1 + e1 ) * ( 1 +e2 ) * .........* ( 1 +en ); sum (n * n) = ( 1

hdu 1104 数论+bfs

题意:给n,m,k;输出n经过+-*%后(n%k+k)%k==((n+1)%k)%k  输出最小路径与运算副 zsd:% 只是求余数 有正负 mod 是求模 无正负. yhd:对m*k求余对 对k求余不对 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 5

hdu 1005 数论 循环

给定 ab 与飞 f1 f2 求f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7. 分析: 1 因为mod7   0<=f(n)  &&f(n)<=6  有7种取值 2 f(n-1) 与f(n-2) 共有49种组合 所以找到循环取值即可 Problem : 1005 ( Number Sequence ) Judge Status : Accepted RunId : 9085676 Language : G++ Author : xiaon

hdu 1664(数论+同余搜索+记录路径)

Different Digits Time Limit: 10000/4000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1430    Accepted Submission(s): 392 Problem Description Given a positive integer n, your task is to find a positive integer m, w