Problem Description

  1. 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.

Input

  1. Each line will contain one integer n(0 < n < 1000000).

Output

  1. Output the LPF(n).

Sample Input

  1. 1 2 3 4 5

Sample Output

  1. 0 1 2 1 3

问数的编号,素数的话就是第几个素数就是他的编号如 2-1 3-2 5-3 7-4非素数就是最小的素因子的序号是他的序号。修改后的线筛完事。

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. #define N 1000005
  5. int prime[N], cnt;
  6. bool vis[N];
  7. int num[N], e[N], tot = 1;
  8. void init()
  9. {
  10. for (int i = 2; i <= N; ++i)
  11. {
  12. if (!vis[i])
  13. {
  14. prime[++cnt] = i;
  15. num[i] = i + 1;
  16. e[i] = tot++;
  17. }
  18. for (int j = 1; j <= cnt; ++j)
  19. {
  20. if (prime[j] * i > N)
  21. break;
  22. vis[prime[j] * i] = true;
  23. e[prime[j] * i] = e[i];
  24. }
  25. }
  26. }
  27. int main()
  28. {
  29. init();
  30. int n;
  31. while (scanf("%d", &n) != EOF)
  32. {
  33. printf("%lld\n", e[n]);
  34. }
  35. }

数学--数论--HDU2136 Largest prime factor 线性筛法变形的更多相关文章

  1. [暑假集训--数论]hdu2136 Largest prime factor

    Everybody knows any number can be combined by the prime number. Now, your task is telling me what po ...

  2. [HDU2136] Largest prime factor(素数筛)

    传送门 题意 给出若干个数n(n<=1000000),求每个n的最大质因子的排名. 质数的排名:如果素数p是第k小的素数,那么p的排名就是k. 思路 乍一看不知道怎么搞. 其实可以想想我们怎么筛 ...

  3. 【沙茶了+筛选保存最大质因数】【HDU2136】Largest prime factor

    Largest prime factor Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  4. The largest prime factor(最大质因数)

    1. 问题: The prime factors of 13195 are 5, 7, 13 and 29.What is the largest prime factor of the number ...

  5. HDOJ(HDU) 2136 Largest prime factor(素数筛选)

    Problem Description Everybody knows any number can be combined by the prime number. Now, your task i ...

  6. (Problem 3)Largest prime factor

    The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 60085 ...

  7. 2136 Largest prime factor(打表)

    Problem Description Everybody knows any number can be combined by the prime number.Now, your task is ...

  8. Largest prime factor

    problem 3:Largest prime factor 题意:求600851475143的最大的质因数 代码如下: #ifndef PRO3_H_INCLUDED #define PRO3_H_ ...

  9. Problem 3: Largest prime factor

    The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 60085 ...

随机推荐

  1. (js描述的)数据结构[哈希表1.1](8)

    (js描述的)数据结构[哈希表1.1](8) 一.数组的缺点 1.数组进行插入操作时,效率比较低. 2.数组基于索引去查找的操作效率非常高,基于内容去查找效率很低. 3.数组进行删除操作,效率也不高. ...

  2. wireshark抓包实战(二),第一次抓包

    1.选择网卡. 因为wireshark是基于网卡进行抓包的,所以这时候我们必须选取一个网卡进行抓包.选择网卡一般有三种方式 (1)第一种 当我们刚打开软件是会自动提醒您选择,例如: (2)第二种 这时 ...

  3. Linux基础篇,正则表达式

    一.正则表达式特殊符号: 二.grep的用法 grep [-A|B|a|c|i|n|v] [--color=auto] '搜索字串' filename -A ===> after缩写,后面接数字 ...

  4. 三、Pycharm2019.3.3的安装

    一:什么是Pycahrm PyCharm是一种Python IDE,带有一整套可以帮助用户在使用Python语言开发时提高其效率的工具,比如调试.语法高亮.Project管理.代码跳转.智能提示.自动 ...

  5. 萌新带你开车上p站(三)

    本文作者:萌新 前情回顾: 萌新带你开车上p站(一) 萌新带你开车上p站(二) 0x08 题目给的提示是和运算符优先级有关 登录后直接看源码 mistake@pwnable:~$ ls flag mi ...

  6. Python财经数据接口包TuShare的使用

    安装TuShare 方式1:pip install tushare 方式2:访问https://pypi.python.org/pypi/tushare/下载安装 方式3:将源代码下载到本地pytho ...

  7. 关于 System.IO.File.Exists 需要注意的事项

    各位:   .NET Framework 本省在设计的时候,他对于异常没有完全做到抛出,这样可能会有很多意想不到的问题.   比如 你在asp.net 应用程序中判断文件是否存在,这个文件可能是一个共 ...

  8. XML布局界面

    Android推荐使用XML布局文件来定义用户界面,而不是使用Java代码来开发用户界面,因此基础所有组件都提供了两种方式来控制组件的行为:1.在XML布局文件中通过XML属性进行控制:2.在Java ...

  9. TcxGrid

    一.列的宽度为64时,其宽度会自动根据字段的长度调整,设置其他值即为固定值: 二.cell中显示按钮:选中某列,在properties中更改为ButtonEdit,点击子属性buttons添加butt ...

  10. Video tagging systems based on DNNs

    Need: With the ever-growth large-scale video in the mobile phone, so what will everyone get from the ...