hdu-5750 Dertouzos(数论)
题目链接:
Dertouzos
Time Limit: 7000/3500 MS (Java/Others)
Memory Limit: 131072/131072 K (Java/Others)
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.
The first line contains two integers n and d (2≤n,d≤109).
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
//#include <bits/stdc++.h>
#include <stack> using namespace std; #define For(i,j,n) for(int i=j;i<=n;i++)
#define mst(ss,b) memset(ss,b,sizeof(ss)); typedef long long LL; template<class T> void read(T&num) {
char CH; bool F=false;
for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p) {
if(!p) { puts("0"); return; }
while(p) stk[++ tp] = p%10, p/=10;
while(tp) putchar(stk[tp--] + '0');
putchar('\n');
} const LL mod=1e9+7;
const double PI=acos(-1.0);
const int inf=1e9;
const int N=1e5+10;
const int maxn=500+10;
const double eps=1e-8; int prime[N],sum[N],a[N],cnt=0,n,d;
void Init()
{
sum[1]=0;
For(i,2,N-maxn)
{
if(!prime[i])
{
for(int j=2*i;j<N-maxn;j+=i)
{
prime[j]=1;
}
sum[i]=sum[i-1]+1;
}
else sum[i]=sum[i-1];
}
For(i,2,N-maxn)
{
if(!prime[i])a[++cnt]=i;
}
} inline int check(int x)
{
for(int i=1;i<=cnt;i++)
{
if(x%a[i]==0)return a[i];
if((LL)a[i]*a[i]>x||a[i]>n/d)break;
}
return x;
}
int main()
{
int t;
read(t);
Init();
while(t--)
{
read(n);read(d);
n--;
int le=min(check(d),n/d);
printf("%d\n",sum[le]);
} return 0;
}
hdu-5750 Dertouzos(数论)的更多相关文章
- hdu 5750 Dertouzos 素数
Dertouzos Time Limit: 7000/3500 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total ...
- BestCoder HDU 5750 Dertouzos
Dertouzos 题意: 有中文,不说. 题解: 我看了别人的题解,还有个地方没懂, 为什么是 if(d%prime[i]==0) break; ? 代码: #include <bits/st ...
- HDU 5750 Dertouzos
Dertouzos Time Limit: 7000/3500 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total ...
- HDU 5750 Dertouzos 简单数学
感悟:这又是zimpha巨出的一场题,然后04成功fst(也就是这题) 实际上还是too young,要努力增加姿势, 分析:直接枚举这些数不好枚举,换一个角度,枚举x*d,也就是d的另一个乘数是多少 ...
- 题解报告:hdu 5750 Dertouzos(最大真约数、最小素因子)
Problem Description A positive proper divisor is a positive divisor of a number n, excluding n itsel ...
- hdu 5750(数论)
Dertouzos Time Limit: 7000/3500 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total ...
- 【HDU 5750】Dertouzos(数学)
题目给定n和d,都是10的9次方以内,求1到n里面有几个数最大因数是d?1000000组数据.解:求出d的满足p[i]*d<n的最小质因数是第几个质数.即为答案. #include<cst ...
- hdu GuGuFishtion 6390 数论 欧拉函数
题目:http://acm.hdu.edu.cn/showproblem.php?pid=6390 直接开始证明: 我们设…………………………………….....…...............………… ...
- HDU 1299 基础数论 分解
给一个数n问有多少种x,y的组合使$\frac{1}{x}+\frac{1}{y}=\frac{1}{n},x<=y$满足,设y = k + n,代入得到$x = \frac{n^2}{k} + ...
- HDU 5317 RGCDQ (数论素筛)
RGCDQ Time Limit: 3000MS Memory Limit: 65536KB 64bit IO Format: %I64d & %I64u Submit Status ...
随机推荐
- fastscripT实现权限控制
fastscripT权限控制 此处以FASTSCRIPT实现功能权限为例,用脚本实现数据权限也是很方便的. unit Unit1; interface uses Winapi.Windows, Win ...
- epoll 浅析以及 nio 中的 Selector
首先介绍下epoll的基本原理,网上有很多版本,这里选择一个个人觉得相对清晰的讲解(详情见reference): 首先我们来定义流的概念,一个流可以是文件,socket,pipe等等可以进行I/O操作 ...
- Android GC 原理探究
导语 想写一篇关于 android GC 的想法来源于追查一个魅族手机图片滑动卡顿问题,由于不断的 GC 导致的丢帧卡顿的问题让我们想了很多方案去解决,所以就打算详细的看看内存分配和 GC 的原理,为 ...
- intellij idea 的常用有用快捷键
ctrl + R:替换(这一点和office 中的ctrl + H不一样) ctrl + alt + L:自动整理代码(不会整理注释文件) ctrl + alt:(自动导入包,不能批量导入,有人评论批 ...
- Hibernate调试——定位查询源头
本文是我在importNew翻译的文章,首发在importNew,这里会定期更新链接. 为什么有时Hibernate会在程序某一部分生成一条指定sql查询?这个问题让人非常难立马理解.当处理不是我们本 ...
- hdu1034 简单模拟
这里开一个二维数组.num[105][2]; 我也不知道N有多少,随便开的, 那么这里num[i][0] 表示当前 第 i 个人拥有的糖果数,num[i][1]表示他上面一个人分给他的糖果数.详 ...
- HDOJ题目2089 不要62(数位DP)
不要62 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submi ...
- solaris用户与文件权限管理
此文章已于 20:45:28 2015/3/22 重新发布到 zhuxuekui3 solaris用户与文件权限管理1 类别 「网站分类」Oracle 一.用户与用户组管理 三种用户:超级用户. ...
- python(21)- python内置函数练习
题目一:用map来处理字符串列表啊,把列表中所有人都变成sb,比方alex_sbname=['alex','wupeiqi','yuanhao'] name=['alex','wupeiqi','yu ...
- vim 自动补全
1. vim编辑器自带关键字补全 触发: ctrl + n or ctrl + p 补全命令: <C-n> 普通关键字 [能够根据buffer以及标签文件列表等 ...