zoukankan      html  css  js  c++  java
  • 2804 最大最小数质因数

    2804 最大最小数质因数

     

    时间限制: 1 s
    空间限制: 64000 KB
    题目等级 : 黄金 Gold
     
     
     
    题目描述 Description

        先输入n,n<=20;再依次输入n个不同的数,每个数<=1000000;找出最大数和最小数,并输出最大最小数的质因数,没有质因数则输出0。

    输入描述 Input Description

    数n,空行,输入n个数,每个数中间空行;

    输出描述 Output Description

    最大数的质因数,每个数中间空格;
    最小数的质因数,每个数中间空格.

    样例输入 Sample Input

    2
    15 6

    样例输出 Sample Output

    3 5
    2 3

    数据范围及提示 Data Size & Hint

     1 #include<iostream>
     2 using namespace std;
     3 #include<cmath>
     4 #include<cstdio>
     5 bool pd(int n)
     6 {
     7     for(int i=2;i<=sqrt(n);++i)
     8         if(n%i==0)return false;
     9     return true;
    10 }
    11 void zy(int x)
    12 {
    13     int t=x;
    14     if(x==1||pd(x))
    15     {
    16         printf("0
    ");
    17         return;
    18     }
    19     for(int i=2;i<=x/2;i++)
    20         if(x%i==0&&pd(i))
    21         {
    22             printf("%d ",i);
    23             t=t/i;
    24             if(t==1) break;
    25         }
    26     printf("
    ");
    27 }
    28 int main()
    29 {    
    30     int n,m,minn=2100000000,maxx=0;
    31     cin>>n;
    32     for(int i=1;i<=n;++i)
    33     {
    34         cin>>m;
    35         if(m>maxx)maxx=m;
    36         if(m<minn)minn=m;
    37     }
    38     zy(maxx);zy(minn);
    39     return 0;
    40 } 
  • 相关阅读:
    【病毒分析】21766239b79ece18b15a03f4517f3be6ed9c07ed
    csu1079
    数组栈coj 1019
    csu1007
    快速排序
    两大数相加
    csu1212 快排
    csu1215
    如何在IIS6,7中部署ASP.NET网站
    webpack快速入门——CSS进阶:自动处理CSS3前缀
  • 原文地址:https://www.cnblogs.com/mjtcn/p/6674963.html
Copyright © 2011-2022 走看看