HDU2710 Max Factor

题意:求输入的n个数中所含素因子最大的数字。

注意:此题中1也是素数。

思路:数据不算太大,朴素判断素数即可。

   max标记最大素因子。

   pos标记所含最大素因子的数。

#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int f(int n)
{
    for(int i = 2; i < n; i++)
        if(n%i==0)
            return 0;
    return 1;
}
int main(void)
{
    int t;
    while(~scanf("%d",&t))
    {
        int pos = 0;
        int max = 0;
        while(t--)
        {
            int n;
            scanf("%d",&n);
            for(int i = 1; i <= n; i++)
            {
                if(n%i==0&&f(i))
                {
                    if(max<i)
                    {
                        max = i;
                        pos = n;
                    }
                }
            }
        }
        printf("%d\n",pos);
    }
    return 0;
}

原文地址:https://www.cnblogs.com/AC-AC/p/9739578.html

时间: 2024-10-14 22:41:21

HDU2710 Max Factor的相关文章

抓其根本(hdu2710 Max Factor 素数 最大公约数 最小公倍数.....)

素数判断: 一.根据素数定义,该数除了1和它本身以外不再有其他的因数. 详见代码. 1 int prime() 2 { 3 for (int i=2; i*i<=n; i++) 4 { 5 if (n%i==0) //不是素数 6 return 1; //返回1 7 } 8 return 0; //是素数返回0 9 } 二.打表,将所有的素数一一列出,存在一个数组里. 详见代码. 1 void prime() 2 { 3 for (int i=2; i<20050; i++) //从2开始一个

POJ3048 HDU2710 Max Factor

筛选法不仅能够用来计算最小的若干素数,也可以用来求整数的最大公因子. 问题链接:POJ3048 HDU2710 Max Factor.基础训练级的题,用C语言编写. 问题简述:测试数据有多组,每组先输入n,然后输入n个正整数,输出n个正整数中,素因子最大的那个数. 问题分析:可以使用类似于筛选法的过程求得一定范围内的各个整数的最大素因子. 程序中,打表是合适的.数组mpf[]中存放最大素因子,若mpf[i]=x,则x为i的最大素因子. AC通过的C语言程序如下: /* POJ3048 HDU27

HDU2710 Max Factor【水题】【素因子】

Max Factor Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4110    Accepted Submission(s): 1342 Problem Description To improve the organization of his farm, Farmer John labels each of his N (1

hdu 2710 Max Factor(找最大素数)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2710 Problem Description To improve the organization of his farm, Farmer John labels each of his N (1 <= N <= 5,000) cows with a distinct serial number in the range 1..20,000. Unfortunately, he is unawa

HDU 2710 Max Factor 数论(水

Max Factor Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Description To improve the organization of his farm, Farmer John labels each of his N (1 <= N <= 5,000) cows with a distinct serial number in the range 1..20

HDU 2710 Max Factor (筛选求素数)

Max Factor Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3995    Accepted Submission(s): 1301 Problem Description To improve the organization of his farm, Farmer John labels each of his N (1

POJ3048 Max Factor

本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000作者博客:http://www.cnblogs.com/ljh2000-jump/转载请注明出处,侵权必究,保留最终解释权!   Description To improve the organization of his farm, Farmer John labels each of his N (1 <= N <= 5,000) cows with a distinct s

HDOJ/HDU 2710 Max Factor(素数快速筛选~)

Problem Description To improve the organization of his farm, Farmer John labels each of his N (1 <= N <= 5,000) cows with a distinct serial number in the range 1..20,000. Unfortunately, he is unaware that the cows interpret some serial numbers as be

POJ 3048 Max Factor (筛素数)

Description To improve the organization of his farm, Farmer John labels each of his N (1 <= N <= 5,000) cows with a distinct serial number in the range 1..20,000. Unfortunately, he is unaware that the cows interpret some serial numbers as better tha