forked from iRupam/NewtonSchoolInfinityJune21
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrimeNumber4.java
More file actions
35 lines (31 loc) · 896 Bytes
/
PrimeNumber4.java
File metadata and controls
35 lines (31 loc) · 896 Bytes
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
package InfinityJune21.BasicMaths.PrimeNumbers;
public class PrimeNumber4 {
public static void main(String[] args) {
int n = 1000001;
int squareRoot = (int)Math.sqrt(n);
int count = 0;
long startTime = System.nanoTime();
if(n == 2) {
count = 0;
}
else if(n % 2 == 0) {
count = 1;
}
else {
for(int i = 3; i <= squareRoot; i+=2) {
if(n % i == 0) {
count++;
}
}
}
long endTime = System.nanoTime();
long totalTime = endTime - startTime;
System.out.println("Total Time: " + totalTime);
if(count == 0) {
System.out.println("Prime Number");
}
else {
System.out.println("Composite Number");
}
}
}