<script>
function
spf_array(arr , N) {
var
i = 0;
for
(i = 1; i <= N; i++) {
arr[i] = i;
}
for
(i = 2; i <= N; i = i + 2) {
arr[i] = 2;
}
for
(i = 3; i * i <= N; i++) {
if
(arr[i] == i) {
var
j = 0;
for
(j = i * i; j <= N; j = j + i) {
if
(arr[j] == j) {
arr[j] = i;
}
}
}
}
}
class node {
constructor(val) {
this
.data = val;
this
.left =
null
;
this
.right =
null
;
}
}
function
newnode(i) {
var
temp =
null
;
temp =
new
node();
temp.val = i;
temp.left =
null
;
temp.right =
null
;
return
temp;
}
function
prime_tree( root , arr) {
var
a = -1;
if
(root !=
null
) {
if
(root.val <= 3 || arr[root.val - 2] != root.val - 2) {
return
0;
}
}
if
(root.left !=
null
) {
a = prime_tree(root.left, arr);
if
(a == 0) {
return
0;
}
}
if
(root.right !=
null
) {
a = prime_tree(root.right, arr);
if
(a == 0) {
return
0;
}
}
return
1;
}
root = newnode(9);
root.right = newnode(7);
root.right.right = newnode(5);
root.right.left = newnode(13);
root.left = newnode(15);
root.left.left = newnode(19);
root.left.right = newnode(25);
var
n = 50;
var
brr = Array(n + 1).fill(0);
var
i = 0;
spf_array(brr, n);
if
(prime_tree(root, brr) == 1) {
document.write(
"Yes"
+
"\n"
);
}
else
{
document.write(
"No"
+
"\n"
);
}
</script>