-
Notifications
You must be signed in to change notification settings - Fork 0
/
B.c
74 lines (50 loc) · 1.07 KB
/
B.c
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
/************************
Prime Time Again
*************************/
#include<stdio.h>
#include<math.h>
int is_prime(int);
int main(int argc, char* argv[])
{
int D; // Day Hours
int P; // Number of parts of a day
int N; // Hours in one parts
int count; // counter for prime_array[] elements
int output_count=0; // Counter for output;
int prime_array[500]; // To store the prime numbers
int i=0,j=0,temp=0,flag=0;
scanf("%d",&D);
scanf("%d",&P);
// Condition Checking
if(D<10 || D >499 || P<2 || P>49) return 1;
//Get the primes
N=D/P;
for(i=0;i<=N;i++) if(is_prime(i)==1) prime_array[count++]=i;
for(i=0;i<count;i++)
{
flag=0;
temp=prime_array[i];
for(j=1;j<P;j++)
{
temp=temp+N;
if(is_prime(temp)==1) flag=1;
else
{
flag=0;
break;
}
}
if(flag==1) output_count++;
}
// Output Display
printf("%d",output_count);
return 0;
}
int is_prime(int number)
{
int i;
if(number<2) return 0;
if(number==2 || number==3) return 1;
else for(i=2;i<=number/2;i++) if(number%i==0) return 0;
return 1;
}