-
Notifications
You must be signed in to change notification settings - Fork 0
/
math.h
71 lines (59 loc) · 1.01 KB
/
math.h
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
70
71
/*******************************************************
lib/math.h
Created at: Feb 25, 2023, 11:24 AM GMT+9
Copyright (C) 2023 e6nlaq
This file is part of aqua.
Licensed under the MIT License.
*******************************************************/
#pragma once
#include "./type.h"
#include <math.h>
inline ll a_gcd(const ll a, const ll b)
{
if (b == 0)
{
return a;
}
else
{
return a_gcd(b, a % b);
}
}
inline ll a_lcm(const ll a, const ll b)
{
return a * b / a_gcd(a, b);
}
inline bool is_prime(const ll num)
{
if (num < 2)
return false;
else if (num == 2)
return true;
else if (num % 2 == 0)
return false; // 偶数はあらかじめ除く
long double sqrtNum = sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2)
{
if (num % i == 0)
{
// 素数ではない
return false;
}
}
// 素数である
return true;
}
inline ll fact(ll x)
{
ll ret = 1;
for (ll i = 1; i <= x; i++)
{
ret *= i;
}
return ret;
}
inline ld log_a(ld x, ld b)
{
return log10l(x) / log10l(b);
}