HDU 5750 Dertouzos 简单数学
感悟:这又是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 简单数学的更多相关文章
- 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 1840 Equations (简单数学 + 水题)(Java版)
Equations 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1840 ——每天在线,欢迎留言谈论. 题目大意: 给你一个一元二次方程组,a(X^2 ...
- 题解报告:hdu 5750 Dertouzos(最大真约数、最小素因子)
Problem Description A positive proper divisor is a positive divisor of a number n, excluding n itsel ...
- HDU 5073 Galaxy (2014 Anshan D简单数学)
HDU 5073 Galaxy (2014 Anshan D简单数学) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5073 Description G ...
- hdu 2200 Eddy's AC难题(简单数学。。)
题意: N个人,每个人AC的题数都不一样. Eddy想从中选出一部分人(或者全部)分成两组.必须满足第一组中的最小AC数大于第二组中的最大AC数. 问共有多少种不同的选择方案. 思路: 简单数学.. ...
- HDU 2085 核反应堆 --- 简单递推
HDU 2085 核反应堆 /* HDU 2085 核反应堆 --- 简单递推 */ #include <cstdio> ; long long a[N], b[N]; //a表示高能质点 ...
- 洛谷试炼场-简单数学问题-P1403 [AHOI2005]-因数
洛谷试炼场-简单数学问题 P1403 [AHOI2005]约数研究 Description 科学家们在Samuel星球上的探险得到了丰富的能源储备,这使得空间站中大型计算机"Samuel I ...
随机推荐
- SDUT2087离散事件模拟-银行管理
呃,这个题,我只想仰天长啸:无语死我了,还动用了繁和帅锅给我改,妹的,做题一定要仔细仔细再仔细啊,这种小错误都犯真是该打. 题目描述 现在银行已经很普遍,每个人总会去银行办理业务,一个好的银行是要考虑 ...
- mysql的学习记录
1 MySQL -h localhost -u UserName -p Password-h不写,默认为localhost注意:最好先MySQL -h localhost -u UserName -p ...
- java实现大数加法、乘法(BigDecimal)
之前写过用vector.string实现大数加法,现在用java的BigDecimal类,代码简单很多.但是在online-judge上,java的代码运行时间和内存大得多. java大数加法:求a+ ...
- 银联接口(注意项&备忘)
1,参考文档“证书下载.导出及上传流程.docx” 按照文档上所述,依次进行,导出的证书备用,用于配置文件的项“const SDK_ENCRYPT_CERT_PATH” 2,使用tp框架 新建一个控制 ...
- shutdown -s -t
import java.io.*; import java.awt.*; public class HackDemo{ public static void main(String args[])th ...
- Apache HTTP Server安装
http://blog.csdn.net/wqmain/article/details/8941759 很清楚,很详细,配置连行号都有.下载的时候直接点击链接即可.
- PowerDesigner连接Oracle数据库建表序列号实现自动增长
原文:PowerDesigner连接Oracle数据库建表序列号实现自动增长 创建表就不说了.下面开始介绍设置自动增长列. 1 在表视图的列上创建.双击表视图,打开table properties — ...
- 244. Shortest Word Distance II
题目: This is a follow up of Shortest Word Distance. The only difference is now you are given the list ...
- Apache编译与安装 RedHat enterprises 6.2
引自:http://blog.chinaunix.net/uid-26881541-id-3336614.html http://apr.apache.org/download.cgi 命令: yum ...
- 在Ubuntu上为Android系统编写Linux内核驱动程序(老罗学习笔记1)
这里,我们不会为真实的硬件设备编写内核驱动程序.为了方便描述为Android系统编写内核驱动程序的过程,我们使用一个虚拟的硬件设备,这个设备只有一个4字节的寄存器,它可读可写.想起我们第一次学习程序语 ...