الأجوبة
/*Write a C program to check if a given number is nearly prime or not*/
#include <stdio.h>
#define NUM_OF_PRIMES 3500
int is_prime(int num);
int main(void)
{
int primes[NUM_OF_PRIMES], num_of_primes = 0;
primes[num_of_primes++] = 2;
for(int num = 3; num * num<= 1000000000; num++)
{
int flag = 1;
for(int id = 0; id <num_of_primes; id++)
{
if(num % primes[id] == 0)
{
flag = 0;
break;
}
}
if(flag) primes[num_of_primes++] = num;
}
int N, num;
scanf("%d", &num);
int flag = 0;
for(int j = 0; (j <num_of_primes) && (primes[j] * primes[j] <= num); j++)
{
if(num % primes[j] == 0)
{
num /= primes[j];
flag = 1;
break;
}
}
if(flag &&is_prime_num(num)) printf("It is a Nearly prime number.\n");
else printf("It is not a Nearly prime number.\n");
return 0;
}
int is_prime_num(int num)
{
if(num != 2 &&num % 2 == 0) return 0;
for(int factor = 3; factor * factor <= num ; factor += 2)
{
if(num % factor == 0) return 0;
}
return 1;
}
القوائم الدراسية التي ينتمي لها السؤال