HDOJ 1164 Eddy's research I

【题意】:对一个数进行因式分解。

【思路】:打表后一个一个除,最大数是65535,所以10000的质数范围苟用。

【AC代码】:

#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iomanip>
using namespace std;

#define MAX 10000

int cnt;
int prime_list[MAX];

int isPrime(int x)
{
    int i = 0;
    for (i = 2; i <= sqrt(x*1.0); i++)
    {
        if (0 == x%i)
            return 0;
    }
    return 1;
}

void MakeList()
{
    int i = 0;
    for (i = 2; i < 65535; i++)
    {
        if (isPrime(i))
            prime_list[cnt++] = i;
    }
}

int main()
{
    int x = 0;
    MakeList();
    while (cin >> x)
    {
        int i = 0;
        int flag = 1;
        while (x != 1)
        {
            for (i = 0; i < cnt; i++)
            {
                if (0 == x%prime_list[i])
                {
                    if (flag)
                        cout << prime_list[i];
                    if (!flag)
                        cout << "*" << prime_list[i];
                    flag = 0;
                    x /= prime_list[i];
                    break;
                }
            }
        }
        cout << endl;
    }
    return 0;
}

注意:error C2668: "sqrt" : 对重载函数的调用不明确。是由于sqrt调用里边如果是int,比如乘1.0转换成double.

HDOJ 1164 Eddy's research I

时间: 2024-10-14 10:19:32

HDOJ 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 1164 Eddy&#39;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 ext

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

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): 7389    Accepted Submission(s): 4472 Problem Description Eddy's interest is very extensive, recently he is interested in prime n

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

HDOJ 1163 Eddy&#39;s digital Roots(简单数论)

[思路]:http://blog.csdn.net/iamskying/article/details/4738838 求解思路: 现在分析一个问题,假设将十位数为a,个位数为b的一个整数表示为ab,则推导得 ab*ab = (a*10+b)*(a*10+b) = 100*a*a+10*2*a*b+b*b 根据上式可得:root(ab*ab) = a*a+2*a*b+b*b = (a+b)*(a+b);[公式一] 同理也可证得:root(ab*ab*ab) = (a+b)*(a+b)*(a+b)

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

hdoj 1162 Eddy&#39;s picture

并查集+最小生成树 Eddy's picture Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 7669    Accepted Submission(s): 3882 Problem Description Eddy begins to like painting pictures recently ,he is sure of hi