感悟:这又是zimpha巨出的一场题,然后04成功fst(也就是这题)

实际上还是too young,要努力增加姿势,

分析:直接枚举这些数不好枚举,换一个角度,枚举x*d,也就是d的另一个乘数是多少

显然  x<=min(d,(n-1)/d),x还得是质数,最后发现x必须小于d的最小因子

然后预处理10w以内的素数,然后每次先得到k=min(d,(n-1)/d),然后看d最小因子是否小于k

这题的关键就在找d的最小因子,我是暴力找的(然后碰上全是大素数就t了)

实际上当d是大素数的时候,k很小,直接枚举质数,如果大于k还没有,就不用再找了(反正去最小)

赛后加上这一个限制就过了

吐槽:还是年轻

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <vector>
#include <math.h>
#include <stack>
#include <map>
#define x first
#define y second
using namespace std;
typedef long long LL;
const int N = 1e5+;
const int INF = 0x3f3f3f3f;
typedef pair<int,int>pii;
bool vis[N];
int prime[N>>],tot;
void getprime(){
for(int i=;i*i<=N-;++i){
if(vis[i])continue;
for(int j=i*i;j<=N-;j+=i)
vis[j]=true;
}
for(int i=;i<=N-;++i)
if(!vis[i])prime[++tot]=i;
}
int main(){ getprime();
int T;
scanf("%d",&T);
while(T--){
int n,d;
scanf("%d%d",&n,&d);
int tmp=min(d,(n-)/d);
int flag=-;
for(int i=;i<=tot&&prime[i]<=tmp&&1ll*prime[i]*prime[i]<=d;++i){
if(d%prime[i])continue;
else {flag=prime[i];break;}
}
if(flag==-)flag=d;
tmp=min(tmp,flag);
int k=lower_bound(prime+,prime++tot,tmp)-prime;
if(k==tot+||prime[k]>tmp)--k;
printf("%d\n",k);
}
return ;
}

HDU 5750 Dertouzos 简单数学的更多相关文章

  1. hdu 5750 Dertouzos 素数

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

  2. BestCoder HDU 5750 Dertouzos

    Dertouzos 题意: 有中文,不说. 题解: 我看了别人的题解,还有个地方没懂, 为什么是 if(d%prime[i]==0) break; ? 代码: #include <bits/st ...

  3. HDU 5750 Dertouzos

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

  4. HDU 1840 Equations (简单数学 + 水题)(Java版)

    Equations 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1840 ——每天在线,欢迎留言谈论. 题目大意: 给你一个一元二次方程组,a(X^2 ...

  5. 题解报告:hdu 5750 Dertouzos(最大真约数、最小素因子)

    Problem Description A positive proper divisor is a positive divisor of a number n, excluding n itsel ...

  6. HDU 5073 Galaxy (2014 Anshan D简单数学)

    HDU 5073 Galaxy (2014 Anshan D简单数学) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5073 Description G ...

  7. hdu 2200 Eddy's AC难题(简单数学。。)

    题意: N个人,每个人AC的题数都不一样. Eddy想从中选出一部分人(或者全部)分成两组.必须满足第一组中的最小AC数大于第二组中的最大AC数. 问共有多少种不同的选择方案. 思路: 简单数学.. ...

  8. HDU 2085 核反应堆 --- 简单递推

    HDU 2085 核反应堆 /* HDU 2085 核反应堆 --- 简单递推 */ #include <cstdio> ; long long a[N], b[N]; //a表示高能质点 ...

  9. 洛谷试炼场-简单数学问题-P1403 [AHOI2005]-因数

    洛谷试炼场-简单数学问题 P1403 [AHOI2005]约数研究 Description 科学家们在Samuel星球上的探险得到了丰富的能源储备,这使得空间站中大型计算机"Samuel I ...

随机推荐

  1. Using the Repository Pattern with ASP.NET MVC and Entity Framework

    原文:http://www.codeguru.com/csharp/.net/net_asp/mvc/using-the-repository-pattern-with-asp.net-mvc-and ...

  2. Notepad++ 16进制编辑功能

    Notepad++可以编辑PE文件(二进制文件即HEX码),2进制.16进制都可以,通过附加的组件HexEditor即可实现. Hex Editor下载  Hex Editor下载页面,包括各个历史版 ...

  3. 40. Combination Sum II

    题目: Given a collection of candidate numbers (C) and a target number (T), find all unique combination ...

  4. UVa 11524 - InCircle

    推公式 #include <cstdio> #include <cmath> double Cal( double a, double b, double c ) { retu ...

  5. JAVA文件中获取路径及WEB应用程序获取路径方法

    JAVA文件中获取路径及WEB应用程序获取路径方法 1. 基本概念的理解 `绝对路径`:你应用上的文件或目录在硬盘上真正的路径,如:URL.物理路径 例如: c:/xyz/test.txt代表了tes ...

  6. C++STL之整理算法

    这里主要介绍颠倒.旋转.随机排列和分类4中常见的整理算法 1.颠倒(反转) void reverse(_BidIt _First, _BidIt _Last) _OutIt reverse_copy( ...

  7. centos6.5安装mongodb

    搜索正面五个文件,由于MongoDB的redhat国外镜像访问非常慢,下载安装suse版本并安装: mongodb-org-2.6.6-1.i686.rpm mongodb-org-mongos-2. ...

  8. 信息:Could not publish server configuration for Tomcat v6.0 Server at localhost. Multiple Context

    需要把server.xml更正一下,去掉重复的context.或者把整个server文件夹都删掉,重新添加服务器.也可以在server窗口中删除server,再新添加一个server.

  9. Hibernate学习笔记之EHCache的配置

    Hibernate默认二级缓存是不启动的,启动二级缓存(以EHCache为例)需要以下步骤: 1.添加相关的包: Ehcache.jar和commons-logging.jar,如果hibernate ...

  10. 11月下旬poj其他题

    poj1000,poj1003,poj1004,poj1064,poj1218 水题 poj1012:0<k<14——漂亮的打表 poj1651:与能量项链很像的dp poj1159:回文 ...