zoukankan      html  css  js  c++  java
  • [暑假集训--数论]hdu2136 Largest prime factor

    Everybody knows any number can be combined by the prime number. 
    Now, your task is telling me what position of the largest prime factor. 
    The position of prime 2 is 1, prime 3 is 2, and prime 5 is 3, etc. 
    Specially, LPF(1) = 0. 

    InputEach line will contain one integer n(0 < n < 1000000). 
    OutputOutput the LPF(n). 
    Sample Input

    1
    2
    3
    4
    5

    Sample Output

    0
    1
    2
    1
    3

    对x分解质因数,问最大的质因子是第几大质数

    瞎暴力就好

     1 #include<cstdio>
     2 #include<algorithm>
     3 #define LL long long
     4 using namespace std;
     5 inline LL read()
     6 {
     7     LL x=0,f=1;char ch=getchar();
     8     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
     9     while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    10     return x*f;
    11 }
    12 int mk[1000010];
    13 int pp[300010],len;
    14 int rnk[1000010];
    15 int n;
    16 inline void getp()
    17 {
    18     for (int i=2;i<=1000000;i++)
    19     {
    20         if (!mk[i])
    21         {
    22             for (int j=2*i;j<=1000000;j+=i)mk[j]=1;
    23             pp[++len]=i;
    24             rnk[i]=len;
    25         }
    26     }
    27 }
    28 int main()
    29 {
    30     getp();
    31     while (~scanf("%d",&n))
    32     {
    33         if (!mk[n]){printf("%d
    ",rnk[n]);continue;}
    34         int mx=0;
    35         for (int i=1;i<=len;i++)
    36         {
    37             if (pp[i]*pp[i]>n)break;
    38             if (n%pp[i]==0)mx=i;
    39             while (n%pp[i]==0)n/=pp[i];
    40         }
    41         if (n!=1)mx=rnk[n];
    42         printf("%d
    ",mx);
    43     }
    44 }
    hdu 2136
  • 相关阅读:
    自己写的SqlHelper
    宿叶网思路
    phpMyAdmin教程 之 创建新用户/导入/导出数据库
    什么是主机空间?干什么用?
    转 sql注入
    xUtils
    仿360状态,类流量监控桌面浮动显示
    在Yii Framework中利用PHPMailer发送邮件(2011-06-02 14:06:23)
    MD5类库(hex_md5)
    MYSQL的随机查询的实现方法
  • 原文地址:https://www.cnblogs.com/zhber/p/7285547.html
Copyright © 2011-2022 走看看