题意:

给一个正整数N,找最小的M,使得N可以整除M,且N/M是质数。

数据范围:

There are multiple test cases (no more than 1,000). Each case contains only one positive integer N.
N≤1,000,000,000.
Number of cases with N>1,000,000 is no more than 100.

思路:

N=M*prime     故必有M或prime小于等于sqrt(N)。暴力扫一遍就行,,总共要扫两次(其实扫一遍也行,,,,)

*:bestCoder第一题竟然TLE了,,,跪了,,,爆零啊!

代码:

int N;

bool isPrime(int x){
int m=(int)sqrt(x+0.5);
rep(i,2,m) if(x%i==0) return false;
return true;
} int main(){
while(scanf("%d",&N)!=EOF){
if(N<2){
puts("0");
continue;
}
int m=(int)sqrt(N+0.5);
int maxs=-1;
rep(i,1,m) if(N%i==0 && isPrime(N/i)){
maxs=(N/i);
break;
}
rep2(i,m,1) if(N%i==0 && isPrime(i)){
maxs=max(maxs,i);
break;
}
printf("%d\n",N/maxs);
}
}

hdu 5108 Alexandra and Prime Numbers(水题 / 数论)的更多相关文章

  1. hdu 5108 Alexandra and Prime Numbers

    数论题,本质是求出n的最大质因子 #include<time.h> #include <cstdio> #include <iostream> #include&l ...

  2. UESTC--1272--Final Pan's prime numbers(水题)

    Final Pan's prime numbers Time Limit: 1000MS   Memory Limit: 65535KB   64bit IO Format: %lld & % ...

  3. Alexandra and Prime Numbers(思维)

    Alexandra and Prime Numbers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (J ...

  4. HDU 2096 小明A+B --- 水题

    HDU 2096 /* HDU 2096 小明A+B --- 水题 */ #include <cstdio> int main() { #ifdef _LOCAL freopen(&quo ...

  5. POJ.2739 Sum of Consecutive Prime Numbers(水)

    POJ.2739 Sum of Consecutive Prime Numbers(水) 代码总览 #include <cstdio> #include <cstring> # ...

  6. HDU 2138 How many prime numbers(Miller_Rabin法判断素数 【*模板】 用到了快速幂算法 )

    How many prime numbers Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/O ...

  7. [HDU 2602]Bone Collector ( 0-1背包水题 )

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 水题啊水题 还给我WA了好多次 因为我在j<w[i]的时候状态没有下传.. #includ ...

  8. HDOJ(HDU) 2138 How many prime numbers(素数-快速筛选没用上、)

    Problem Description Give you a lot of positive integers, just to find out how many prime numbers the ...

  9. VK Cup 2016 - Qualification Round 2 A. Home Numbers 水题

    A. Home Numbers 题目连接: http://www.codeforces.com/contest/638/problem/A Description The main street of ...

随机推荐

  1. 使用IntelliJ工具打包kotlin为bat文件运行报错 Exception in thread "main" java.lang.NoClassDefFoundError

    Exception in thread "main" java.lang.NoClassDefFoundError 这个很有可能是因为idea里的java版本与电脑上的java环境 ...

  2. redis代替mybatis做缓存

    将redis作为缓存 <dependencies> <dependency> <groupId>org.springframework.boot</group ...

  3. python学习笔记(十五)-异常处理

    money = input('输入多少钱:') months = input('还几个月:') try: res = calc(int(money),int(months)) except ZeroD ...

  4. 定要过python二级 选择第3套

    1 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. . 13. 14. 15. 16. 17. (1)说明了一个问题 所谓的方向是从左到右还是从右到左  是看的是步长  步长的 ...

  5. HTML 网页开发、CSS 基础语法——八.HTML基本语法

    表格制作 1.表格基础 创建一个简单的表格至少有三个标签组成,分别是<table>,<tr>,<td>标签. table:表格,定义的是整个的表格大结构. tr:t ...

  6. AT3949-[AGC022D]Shopping【贪心】

    正题 题目链接:https://www.luogu.com.cn/problem/AT3949 题目大意 长度为\(L\)的坐标轴上,给出\(n\)个点,每个点\(x_i\)需要购物\(t_i\)的时 ...

  7. WPF进阶技巧和实战07--自定义元素01

    完善和扩展标准控件的方法: 样式:可使用样式方便地重用控件属性的集合,甚至可以使用触发器应用效果 内容控件:所有继承自ContentControl类的控件都支持嵌套的内容.使用内容控件,可以快速创建聚 ...

  8. 查看显卡报错:NVIDIA-SMI has failed because it couldn't communicate with the NVIDIA driver. Make sure that the latest NVIDIA driver is installed and running.

    当输入nvidia-smi时出现 NVIDIA-SMI has failed because it couldn't communicate with the NVIDIA driver. Make ...

  9. LightningChart XY功能中的常见问题

    LightningChart XY功能中的常见问题 XY 是LightningChart 的重要功能之一,也是被用户使用最广泛的.用户经常对这个功能有着这样那样的疑问,现在将一些常用问题汇总了一下,希 ...

  10. Serverless X OpenKruise 部署效率优化之道

    作者 | 许成铭(竞霄) Serverless 作为云计算的最佳实践.云原生发展的方向和未来演进趋势,其核心价值在于快速交付.智能弹性.更低成本.SAE(Serverless 应用引擎)作为首款面向应 ...