首页 > ACM题库 > HDU-杭电 > HDU 1164 Eddy’s research I[解题报告] C++
2013
12-03

HDU 1164 Eddy’s research I[解题报告] C++

Eddy’s research I

问题描述 :

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 .

输入:

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

输出:

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

样例输入:

11
9412

样例输出:

11
2*2*13*181

2011-12-16 11:30:41

地址:http://acm.hdu.edu.cn/showproblem.php?pid=1164

题意:分解素因子。。。

代码:

# include <stdio.h>


int main ()
{
    int i, n, flag ;
    while (~scanf ("%d", &n))
    {
        flag = 0 ;
        for (i = 2 ; i< n ; i++)
        {
            if (n == 1) break ;
            while (n % i == 0)
            {
                if (flag == 0) flag = 1 ;
                else printf ("*") ;
                printf ("%d", i) ;
                n/=i ;
            }
        }
        if (n != 1) printf (flag?"*%d":"%d", n) ;
        puts ("") ;
    }
    return 0 ;
}


  1. 约瑟夫也用说这么长……很成熟的一个问题了,分治的方法解起来o(n)就可以了,有兴趣可以看看具体数学的第一章,关于约瑟夫问题推导出了一系列的结论,很漂亮

  2. 第一句可以忽略不计了吧。从第二句开始分析,说明这个花色下的所有牌都会在其它里面出现,那么还剩下♠️和♦️。第三句,可以排除2和7,因为在两种花色里有。现在是第四句,因为♠️还剩下多个,只有是♦️B才能知道答案。