1. /*
  2. Problem Description
  3. Everybody knows any number can be combined by the prime number.
  4. Now, your task is telling me what position of the largest prime factor.
  5. The position of prime 2 is 1, prime 3 is 2, and prime 5 is 3, etc.
  6. Specially, LPF(1) = 0.
  7.  
  8. Input
  9. Each line will contain one integer n(0 < n < 1000000).
  10.  
  11. Output
  12. Output the LPF(n).
  13.  
  14. Sample Input
  15. 1
  16. 2
  17. 3
  18. 4
  19. 5
  20.  
  21. Sample Output
  22. 0
  23. 1
  24. 2
  25. 1
  26. 3
  27. */
  28. #include <stdio.h>
  29. #include <string.h>
  30.  
  31. const int N = ;
  32. int hash[N+];
  33. int prime[N+];
  34.  
  35. void sushu()
  36. {
  37. int i,j;
  38. memset(prime,,sizeof(prime));
  39. hash[] = ;
  40. int flag = ;
  41. for(i = ; i<=N; i++)
  42. {
  43. if(!prime[i])
  44. {
  45. hash[i] = ++flag;
  46. for(j = i; j<=N; j+=i)
  47. {
  48. prime[j] = i;
  49. }
  50. }
  51. }
  52. }
  53.  
  54. int main()
  55. {
  56. int i;
  57. memset(hash,,sizeof(hash));
  58. sushu();
  59. while(~scanf("%d",&i))
  60. {
  61. if(i == )
  62. printf("0\n");
  63. else
  64. {
  65. int k = prime[i];
  66. printf("%d\n",hash[k]);
  67. }
  68. }
  69.  
  70. return ;
  71. }

ACM2136的更多相关文章

随机推荐

  1. DS18B20

    DS18B20驱动 [ 2012-5-14 12:01:00 | By: 吴师傅 ]   14 推荐 一.概述 DS18B20是一种单总线数字温度传感器.測试温度范围-55℃-125℃,温度数据位可配 ...

  2. openflow tutorial 开始openflow的学习(一)

    首先不废话介绍openflow了,自己也还搞不清楚究竟是个什么玩意儿,概括不出什么内容来,先做试验,有个大体的感性了解回来再总结吧. 第一步,搭建环境,这一步就是安装工具,不同的系统环境搭建不一致,我 ...

  3. JavaScript的68个技巧一

    1. 严格模式 在自己的项目中 你可以坚持只使用" 严格模式 " 或只使用" 非严格模式 "的策略.但如果你要编写健壮的代码应对各种各样的代码连接 你有两个可选 ...

  4. linux-Python升级安装

    Wget https://www.python.org/ftp/python/3.5.0/Python-3.5.0.tgz tar zxvf Python-3.5.0.tar.gz && ...

  5. 你的sscanf用对了吗

    用sscanf解析输入字符串 我们平常编写的很多应用程序都会处理各种各样的输入,这些输入或来自本地文件,或来自网络,或来自用户的输入.今天,让我们来看看sscanf这个和字符串相关的函数可能给你带来的 ...

  6. java基础之导入(药师点评)

    /** * 药师点评的导入 * @param request * @param response * @param f * @param tmallTcMessageImport * @return ...

  7. Java初转型-Maven入门

    原系列名:Maven学习总结(一) 原博文出自于:http://www.cnblogs.com/xdp-gacl/p/3498271.html 感谢! 一.Maven的基本概念 Maven(翻译为&q ...

  8. TimeSpinner( 时间微调) 组件

    本节课重点了解 EasyUI 中 Spinner(微调)组件的使用方法,这个组件依赖于Spinner(微调)组件. 一. 加载方式//class 加载方式<input id="box& ...

  9. 3.Android Studio系列教程3——快捷键

    原文链接:http://stormzhang.com/devtools/2014/12/09/android-studio-tutorial3/   一.更新Android Studio 项目根目录的 ...

  10. RecycleView 瀑布流滑动移位

    RecycleView StaggeredLayoutManager(瀑布流)滑动的时候,默认会出现item移动的问题,需以下来个步骤来解决: 附上StaggeredLayoutManager中的一段 ...