# UVa 11466 - Largest Prime Divisor

如果最後下的數字不是1，則它就是最大的素數因子。

#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>

using namespace std;

int visit[10000001];
int prime[10000001];

int main()
{
memset(visit, 0, sizeof(visit));
int count = 0;
for (int i = 2; i < 10000001; ++ i) {
if (!visit[i]) prime[count ++] = i;
for (int j = 0; j < count && i*prime[j] < 10000001; ++ j)
visit[i*prime[j]] = 1;
}

long long n,m;
while (cin >> n && n) {
if (n < 0) n = -n;
int size = 0;
for (int i = 0; i < count; ++ i) {
if (n < prime[i]) break;
if (n%prime[i] == 0) {
m = prime[i];
++ size;
while (n%m == 0) n /= m;
}
}
if (n != 1) {
m = n;
++ size;
}

if (size > 1)
cout << m << endl;
else cout << "-1" << endl;
}
return 0;
}


• 本文已收录于以下专栏：

## hdu2136 Largest prime factor

Largest prime factor Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth...

## Largest prime factor

Largest prime factor Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot...

## HDUOJ 2136 Largest prime factor

#include #include #include #include #include #include #include #include #include #include ...

## uva 836 Largest Submatrix

uva 836 Largest Submatrix

## hdu2136 Largest prime factor（C语言）

C语言AC代码 #include #include int a[1000005]; void getprimers() { memset(a,0,sizeof(a)); a[1]=0;...

## 杭电OJ 2136 Largest prime factor

Largest primefactor Problem Description Everybody knowsany number can be combined by the prime num...

## UVA - 10650 ：Determinate Prime

Description   Determinate Prime Input: standard input Output: standard output Time Limit: 1...

举报原因： 您举报文章：深度学习：神经网络中的前向传播和反向传播算法推导 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)