-
Notifications
You must be signed in to change notification settings - Fork 0
/
other.cpp
69 lines (65 loc) · 996 Bytes
/
other.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <iostream>
#include <cmath>
using namespace std;
//实现乘方
double mypow(double base,int ex)
{
if(base == 0)
{
return 0;
}
if(0 == ex)
{
return 1;
}
if(ex == 1)
{
return base;
}
double result = mypow(base,ex>>1);
result *= result;
if(ex & 0x1 == 1)
{
result *= base;
}
return result;
}
template <typename T>
bool isfavor(T n)
{
if(n == 1)
{
cout<<"1!!!!"<<endl;
return false;
}
for(T i = sqrt(n); i >= 2; --i)
{
if(n % i == 0)
{
return false;
}
}
return true;
}
//素因子分解
template <typename T>
void favor(T n)
{
if(isfavor(n))
{
cout<<n<<endl;
}
else
{
T result = 0;
for(T i = n/2; i >= 2; --i)
{
if(n%i == 0)
{
favor(i);
favor(n/i);
break;
}
}
}
}