HDU2710(素数打表)
来源:互联网 发布:第五届淘宝村高峰论坛 编辑:程序博客网 时间:2024/05/29 05:01
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2710
解题思路:
打出素数表,找出每个数的最大素因子,取最大的即可。
完整代码:
#include <functional>#include <algorithm>#include <iostream>#include <fstream>#include <sstream>#include <iomanip>#include <numeric>#include <cstring>#include <climits>#include <cassert>#include <complex>#include <cstdio>#include <string>#include <vector>#include <bitset>#include <queue>#include <stack>#include <cmath>#include <ctime>#include <list>#include <set>#include <map>using namespace std;#pragma comment(linker, "/STACK:102400000,102400000")typedef long long LL;typedef double DB;typedef unsigned uint;typedef unsigned long long uLL;/** Constant List .. **/ //{const int MOD = int(1e9)+7;const int INF = 0x3f3f3f3f;const LL INFF = 0x3f3f3f3f3f3f3f3fLL;const DB EPS = 1e-9;const DB OO = 1e20;const DB PI = acos(-1.0); //M_PI;const int maxn = 20001;int a[maxn] , b[maxn];int pri[maxn];int cnt;bool ispri[maxn];void dopri(){ memset(ispri , true , sizeof(ispri)); cnt = 0; ispri[0] = false; ispri[1] = false; for(int i = 2 ; i < maxn ; i ++) { if(ispri[i]) { pri[cnt++] = i; for(int j = i * i ; j < maxn ; j += i) ispri[j] = false; } }}void in(int n){ memset(a , 0 , sizeof(a)); for(int i = 0 ; i < n ; i ++) cin >> a[i];}int solve(int n){ in(n); memset(b , 0 , sizeof(b)); for(int i = 0 ; i < n ; i ++) { int maxx = -INF; for(int j = 0 ; pri[j] <= a[i] ; j ++) { if(a[i] % pri[j] == 0 && pri[j] > maxx) { maxx = pri[j]; } } b[i] = maxx; } int key = 0 , maxx = -INF; for(int i = 0 ; i < n ; i ++) { //cout << b[i] << " " ; if(b[i] > maxx) { maxx = b[i]; key = i; } } //cout << endl; return a[key];}int main(){ #ifdef DoubleQ freopen("in.txt","r",stdin); #endif std::ios::sync_with_stdio(false); std::cin.tie(0); int n; dopri(); while(cin >> n) { cout << solve(n) << endl; }}
0 0
- HDU2710(素数打表)
- hdu2710 (素数删选法)
- Max Factor hdu2710 素数相关
- hdu2710 筛选法求素数
- 素数筛选:HDU2710-Max Factor
- 素数判定 - 素数打表
- hdu2710
- HDU2710
- 打素数表
- 素数打表
- 打素数表
- 高效素数打表
- 素数打表
- 素数打表
- 素数打表
- 素数打表
- 高效素数打表
- 打素数表
- AsyncTask测试多任务
- 关于inline关键字导致的 unresolved external symbol问题
- 让并发和容错更容易:Akka示例教程
- 集合框架概要
- 空间域图像增强
- HDU2710(素数打表)
- LKT5102KEY 32位CPU高速软件加密锁
- linux修改用户权限的方法
- 《Intel汇编语言程序设计》小结1:虚拟机的概念
- 查看网卡信息的两个文件:/proc/net/dev和/proc/net/snmp
- 在SUSE12中使用 Machinery 进行高级系统管理
- KNN算法
- Git图形化界面客户端大汇总
- IPV6联网小技巧