HDU 1405

题意:

  输入一个数n,输出它的素因子与这个素因子出现的次数.

分析:

  用欧拉函数,变下形就好了,不再过多解释.

代码如下:

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <fstream>
 5 #include <ctime>
 6 #include <cmath>
 7 #include <cstdlib>
 8 #include <algorithm>
 9 #include <set>
10 #include <map>
11 #include <list>
12 #include <stack>
13 #include <queue>
14 #include <iterator>
15 #include <vector>
16
17 using namespace std;
18
19 #define LL long long
20 #define INF 0x3f3f3f3f
21 #define MOD 1000000007
22 #define MAXN 10000010
23 #define MAXM 1000010
24
25 const int maxn = 65537;
26 int a[maxn];
27
28 void euler_phi(int n)
29 {
30     int m = (int)sqrt(n+0.5);
31     //int ans = n;
32     for(int i = 2; i <= m; i++ )
33         if(n%i==0)
34         {
35             //ans = ans/i*(i-1);
36             while(n%i==0)
37             {
38                 a[i]++;
39                 n /= i;
40             }
41         }
42     if(n > 1)
43         a[n]++;
44 //        ans = ans/n*(n-1);
45 //    return ans;
46 }
47
48 int main()
49 {
50     int n;
51     int kase = 0;
52     while(scanf("%d", &n)==1&&n>=0)
53     {
54         if(kase)
55             printf("\n");
56         memset(a, 0, sizeof(a));
57         euler_phi(n);
58         printf("Case %d.\n", ++kase);
59         for(int i = 2; i <= n; i++ )
60             if(a[i])
61                 printf("%d %d ", i, a[i]);
62         printf("\n");
63     }
64
65     return 0;
66 }
时间: 2024-11-05 04:48:17

HDU 1405的相关文章

HDU 1405 The Last Practice(数学题,变态的格式)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1405 Problem Description Tomorrow is contest day, Are you all ready? We have been training for 45 days, and all guys must be tired.But , you are so lucky comparing with many excellent boys who have no ch

HDU 1405 The Last Practice

The Last Practice Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 9226    Accepted Submission(s): 1960 Problem Description Tomorrow is contest day, Are you all ready?We have been training for 45

HDU 1405 The Last Practice【注意输出格式】

/* 中文题目 最后的练习 中文翻译-大意 举例说明60%2==0:60/2==30:30%2==0:30/2==15:15%2!=0:15%3==0:15/3==5:5%3!=0:5%5==0:根据例子可以看出60的质子含有2^2, 3^1, 5^1,按样例输出2[]2[]3[]1[]5[]1[]. 解题思路:先打一个素数表,在直接求解就可以了 注意:除第一个数据外,其余输入后要空行:输出格式坑人啊. 关键点:输出格式 解题人:lingnichong 解题时间:2014-08-29 00:33

杭电 HDU ACM 1405 The Last Practice

The Last Practice Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 8374    Accepted Submission(s): 1724 Problem Description Tomorrow is contest day, Are you all ready? We have been training for

HDU分类

模拟题, 枚举 1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 1049 1050 1057 1062 1063 1064 1070 1073 1075 1082 1083 1084 1088 1106 1107 1113 1117 1119 1128 1129 1144 1148 1157 1161 1170 1172 1177 1197 1200 1201 12

转载:hdu 题目分类 (侵删)

转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012.1013.1014.1017.1019.1021.1028.1029. 1032.1037.1040.1048.1056.1058.1061.1070.1076.1089.1090.1091.1092.1093. 1094.1095.1096.1097.1098.1106.1108.1157.116

HDU——PKU题目分类

HDU 模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 1049 1050 1057 1062 1063 1064 1070 1073 1075 1082 1083 1084 1088 1106 1107 1113 1117 1119 1128 1129 1144 1148 1157 1161 1170 1172 1177 1197 1200 1201

HDU 3277 Marriage Match III(拆点+二分+最大流SAP)

这个题目是说,有n个女的和男的找伴侣.然后女的具有主动选择权,每个女的可以选自己喜欢的男的,也可以挑选k个不喜欢的男的,做法就是:把女的拆点,u1->u2建立一条容量为k的边.如果遇见喜欢的男生i->j+2*n建一条容量为1的边,否则i+n->j+2*n建一条容量为1的边.最后将源点和女生相连容量为mid,汇点与男生相连容量为mid.枚举mid,看是否会产生满流. 可能姿势不够优美dinic超时了啊,换成SAP快了很多啊... Marriage Match III Time Limit:

HDU 6203 ping ping ping [LCA,贪心,DFS序,BIT(树状数组)]

题目链接:[http://acm.hdu.edu.cn/showproblem.php?pid=6203] 题意 :给出一棵树,如果(a,b)路径上有坏点,那么(a,b)之间不联通,给出一些不联通的点对,然后判断最少有多少个坏点. 题解 :求每个点对的LCA,然后根据LCA的深度排序.从LCA最深的点对开始,如果a或者b点已经有点被标记了,那么continue,否者标记(a,b)LCA的子树每个顶点加1. #include<Bits/stdc++.h> using namespace std;