HDU 1164 Eddy's research I【素数筛选法】

思路:将输入的这个数分成n个素数的相乘的结果,用一个数组存储起来。之后再输出就可以了

Eddy‘s research I

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 6633    Accepted Submission(s): 3971

Problem Description

Eddy‘s interest is very extensive, recently he is interested in prime number. Eddy discover the all number owned can be divided into the multiply of prime number, but he can‘t write program, so Eddy has to ask intelligent you to help him, he asks you to write
a program which can do the number to divided into the multiply of prime number factor .

Input

The input will contain a number 1 < x<= 65535 per line representing the number of elements of the set.

Output

You have to print a line in the output for each entry with the answer to the previous question.

Sample Input

11
9412

Sample Output

11
2*2*13*181

Author

eddy

#include<stdio.h>
#include<string.h>
int a[55];
int getprime(int x)
{
    memset(a,0,sizeof(a));
    int i,cnt=0;
    for(i=2; i<=x; i++)
    {
        while(x%i==0)
        {
            a[cnt++]=i;
            x=x/i;
        }
    }
    return cnt;
}
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        int k,i;
        k=getprime(n);
        for(i=0; i<k-1; i++)
            printf("%d*",a[i]);
        printf("%d\n",a[k-1]);

    }
    return 0;
} 

HDU 1164 Eddy's research I【素数筛选法】

时间: 2024-10-21 01:34:31

HDU 1164 Eddy's research I【素数筛选法】的相关文章

杭电 HDU 1164 Eddy&#39;s research I

Eddy's research I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7117    Accepted Submission(s): 4268 Problem Description Eddy's interest is very extensive, recently  he is interested in prime

hdu 1164 Eddy&#39;s research I

1 #include<iostream> 2 #include<cstring> 3 #include<cstdio> 4 #include<string> 5 #include<cmath> 6 #include<algorithm> 7 using namespace std; 8 #define MAX 65535 9 int prime[MAX+5]; 10 bool vis[MAX+5]; 11 int index=0; 1

hdu 5407 CRB and Candies(素数筛选法,除法取模(乘法逆元))

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5407 解题思路: 官方题解: The problem is just to calculate g(N) =\ LCM(C(N,0), C(N,1), ..., C(N, N))g(N) = LCM(C(N,0),C(N,1),...,C(N,N)). Introducing function f(n) =\ LCM(1, 2, ..., n)f(n) = LCM(1,2,...,n), the

HDU 1165 Eddy&#39;s research II

Eddy's research II Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 3970    Accepted Submission(s): 1459 Problem Description As is known, Ackermann function plays an important role in the sphere

HDOJ 1164 Eddy&#39;s research I

[题意]:对一个数进行因式分解. [思路]:打表后一个一个除,最大数是65535,所以10000的质数范围苟用. [AC代码]: #include <iostream> #include <cstdlib> #include <cstdio> #include <cmath> #include <algorithm> #include <iomanip> using namespace std; #define MAX 10000 i

hdu 1165 Eddy&#39;s research II(数学题,递推)

// Eddy 继续 Problem Description As is known, Ackermann function plays an important role in the sphere of theoretical computer science. However, in the other hand, the dramatic fast increasing pace of the function caused the value of Ackermann function

HDU 1165 Eddy&#39;s research II (推公式)

Eddy's research II Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 3122    Accepted Submission(s): 1137 Problem Description As is known, Ackermann function plays an important role in the sphere

HDU 1165 Eddy&#39;s research II(递推)

坑了我好久,乍看很简单,记忆化搜索结果爆栈,然后改成递推之后WA . 后来发现,是在计算m=3的数据时出现了错误,因为当m=3时,即使n很小,结果也会很大,所以无法利用m=2时的结果递推,要怎么办呢?  将m=2的结果打印出来可以发现这是一个等差数列,通项为S(n) = 2*n + 3; 这有什么用呢? 我们可以发现,当 m=3时由递推式可以写成A(m,n) = A(2,A(m,n-1)) = 2*A(m,n-1) + 3; 所以只要知道了A(3,0),我们就能递推出所有m=3时的值了 . 细节

HDU 1165 Eddy&#39;s research II(给出递归公式,然后找规律)

- Eddy's research II Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Description As is known, Ackermann function plays an important role in the sphere of theoretical computer science. However, in the other h