-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsample.c
65 lines (58 loc) · 1.47 KB
/
sample.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
#include <stdio.h>
#include <stdlib.h>
struct PrimeNumberNode
{
int prime;
int count;
struct PrimeNumberNode *next;
};
int wasteTime(int factor)
{
int i = 0;
int testResult;
for (i = 0; i < factor; i++)
{
testResult += i;
testResult = testResult * 1;
}
return testResult;
}
// function to get prime number which is very hot
struct PrimeNumberNode *number(int input)
{
int i;
int j;
struct PrimeNumberNode *head = (struct PrimeNumberNode *)malloc(sizeof(struct PrimeNumberNode));
struct PrimeNumberNode *currentNode = head;
for (i = 3; i < input; i++)
{
if (i % 2 == 1)
{
for (j = 2; j < i; j++)
{
int testResult = wasteTime(j);
if (testResult % 10000 == 9999)
printf("Test code");
if (i % j == 0)
continue;
}
struct PrimeNumberNode *primeNode = (struct PrimeNumberNode *)malloc(sizeof(struct PrimeNumberNode));
currentNode->next = primeNode;
currentNode = primeNode;
head->count++;
}
}
return head;
}
int main(int argc, char *argv[])
{
if(argc != 2) {
printf("Error. Input a number.\n");
return 0;
}
printf("input=%d\n", atoi(argv[1]));
struct PrimeNumberNode* head = number(atoi(argv[1]));
printf("%d\n",head->count);
head = number(atoi(argv[1]));
printf("%d\n",head->count);
}