HDU2136最大的素因子在素数表中排第几

来源:互联网 发布:手机怎么注册淘宝店铺 编辑:程序博客网 时间:2024/06/10 16:30
 

HDU2136最大的素因子在素数表中排第几

分类: 数论 55人阅读 评论(0) 收藏 举报

题目:Largest prime factor

 

题意是求一个数的最大素因子在素数表中排第几的问题,比如9的最大素因子是3,在素数表中排第二,5的最大素因子为5,排第三。

[cpp] view plaincopy
  1. #include <stdio.h>  
  2.   
  3. int rank[1100000];  
  4.   
  5. int main()  
  6. {  
  7.     int n,cnt=1;  
  8.     for(int i=2;i<1000001;i++)  
  9.     {  
  10.         if(rank[i])continue;  
  11.         for(int j=i;j<1000001;j+=i)  
  12.            rank[j]=cnt;  
  13.         cnt++;  
  14.     }  
  15.     while(~scanf("%d",&n))  
  16.        printf("%d\n",rank[n]);  
  17.     return 0;  
  18. }  
原创粉丝点击