-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.cpp
More file actions
80 lines (72 loc) · 1.35 KB
/
Copy pathutils.cpp
File metadata and controls
80 lines (72 loc) · 1.35 KB
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
72
73
74
75
76
77
78
79
#include "utils.h"
#include <cmath>
// HCF (Highest Common Factor) using Euclidean algorithm
int hcf(int a, int b)
{
while (b != 0) {
int temp = b;
b = a % b;
a = temp;
}
return a;
}
// LCM (Lowest Common Multiple) calculation
// LCM(a, b) = a * b / HCF(a, b)
int lcm(int a, int b)
{
if (a == 0 || b == 0) {
return 0;
}
return (a * b) / hcf(a, b);
}
// Check if a number is prime
bool isPrime(int n)
{
if (n < 2) {
return false;
}
if (n == 2) {
return true;
}
if (n % 2 == 0) {
return false;
}
// Check divisibility up to sqrt(n)
for (int i = 3; i * i <= n; i += 2) {
if (n % i == 0) {
return false;
}
}
return true;
}
// Validate number for player 1 (range 50-99, non-prime)
bool isValidPlayer1Number(int n)
{
// Check range
if (n < 50 || n > 99) {
return false;
}
// Check if non-prime
if (isPrime(n)) {
return false;
}
return true;
}
// Validate number for player 2 (range 60-99, non-prime)
bool isValidPlayer2Number(int n)
{
// Check range
if (n < 60 || n > 99) {
return false;
}
// Check if non-prime
if (isPrime(n)) {
return false;
}
return true;
}
// Get last digit of a number
int getLastDigit(int n)
{
return abs(n) % 10;
}