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 = ;
bool p[N];
int prime[N];
int id;
void init()
{
id = ;
for(int i=; 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 = ;
for(int i=; i<=id; i++)
{
if(prime[i]*d>=n) break;
ans++;
if(d%prime[i]==) break;
}
printf("%d\n",ans);
}
return ;
}

hdu 5750(数论)的更多相关文章

  1. hdu 5750 Dertouzos 素数

    Dertouzos Time Limit: 7000/3500 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total ...

  2. GCD and LCM HDU 4497 数论

    GCD and LCM HDU 4497 数论 题意 给你三个数x,y,z的最大公约数G和最小公倍数L,问你三个数字一共有几种可能.注意123和321算两种情况. 解题思路 L代表LCM,G代表GCD ...

  3. HDU 4497 数论+组合数学

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4497 解题思路:将满足条件的一组x,z,y都除以G,得到x‘,y',z',满足条件gcd(x',y' ...

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

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=4542 小明系列故事--未知剩余系 Time Limit: 500/200 MS (Java/Others) ...

  5. hdu 4961 数论?

    http://acm.hdu.edu.cn/showproblem.php?pid=4961 给定ai数组; 构造bi, k=max(j | 0<j<i,a j%ai=0), bi=ak; ...

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

    Different Digits Time Limit: 10000/4000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

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

    http://acm.hdu.edu.cn/showproblem.php?pid=3641 学到: 1.二分求符合条件的最小值 /*================================= ...

  8. hdu 4059 数论+高次方求和+容斥原理

    http://acm.hdu.edu.cn/showproblem.php? pid=4059 现场赛中通过率挺高的一道题 可是容斥原理不怎么会.. 參考了http://blog.csdn.net/a ...

  9. 【HDU 5750】Dertouzos(数学)

    题目给定n和d,都是10的9次方以内,求1到n里面有几个数最大因数是d?1000000组数据.解:求出d的满足p[i]*d<n的最小质因数是第几个质数.即为答案. #include<cst ...

随机推荐

  1. lintcode-117-跳跃游戏 II

    117-跳跃游戏 II 给出一个非负整数数组,你最初定位在数组的第一个位置. 数组中的每个元素代表你在那个位置可以跳跃的最大长度. 你的目标是使用最少的跳跃次数到达数组的最后一个位置. 样例 给出数组 ...

  2. Vue组件间通信:一个例子学会Vue组件-Vue.js学习总结)(转载)

    详情请点击 http://www.jianshu.com/p/9ad1ba89a04b

  3. RegExp & bug

    RegExp & bug translated bug // OK && tranlate `/` let new_obj_reg = new RegExp(`^(([^< ...

  4. P1650 田忌赛马

    题目描述 我国历史上有个著名的故事: 那是在2300年以前.齐国的大将军田忌喜欢赛马.他经常和齐王赛马.他和齐王都有三匹马:常规马,上级马,超级马.一共赛三局,每局的胜者可以从负者这里取得200银币. ...

  5. C#范型实例化对象

    T s = System.Activator.CreateInstance<T>();

  6. 【题解】HAOI2008木棍分割

    对于这道题目的两问,第一问直接二分答案求出最短长度.关键在于第二问应当如何求:建立dp方程,dp[i][j]代表到第i个分界线,切了j次(强制在第i处切一刀.这样就不会对后面的状态产生影响).状态转移 ...

  7. 洛谷 P1251 餐巾计划问题

    题目链接 最小费用最大流. 每天拆成两个点,早上和晚上: 晚上可以获得\(r_i\)条脏毛巾,从源点连一条容量为\(r_i\),费用为0的边. 早上要供应\(r_i\)条毛巾,连向汇点一条容量为\(r ...

  8. 周记【距gdoi:110天】

    这两个星期都在复习和考试,进度慢了好多.(考试也觉得似乎不是很理想) 姚老要我们写个程序来应对学校的分班问题.然后我们就脑洞打开准备设计一个.写应用程序应该是很烧时间的吧? 接下来搞搞后缀数组,然后还 ...

  9. hdu4035 Maze 【期望dp + 数学】

    题目链接 BZOJ4035 题解 神题啊...orz 不过网上题解好难看,数学推导不写\(Latex\)怎么看..[Latex中毒晚期] 我们由题当然能很快写出\(dp\)方程 设\(f[i]\)表示 ...

  10. AOJ.800 热身之开关灯

    热身之开关灯 Time Limit: 1000 ms Case Time Limit: 1000 ms Memory Limit: 64 MB Total Submission: 276 Submis ...