/home/toolbox/public_html/solutions/106/10699/fast.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <sys/types.h>
4 #include <sys/stat.h>
5 #include <fcntl.h>
6 #include <stdint.h>
7 #include <math.h>
8 #include <stdlib.h>
9
10 #define TRUE (1 == 1)
11 #define FALSE (1 != 1)
12
13 #define DEBUG if (FALSE)
14
15 #define MAX_PRIMES 78505
16 #define MAX_SIZE 1000002
17
18 /*
19 * Author:
20 * Date: 2005-07-20
21 * Purpose: practice
22 * Problem: 10699
23 */
24
25 /*
26 * This template reads data until a terminating value is reached.
27 */
28
29 int num;
30 int buff[MAX_SIZE] = { 0 };
31
32 int init()
33 {
34 /* FUNCTION init */
35 int i;
36 int j;
37 /*
38 for (i=1; MAX_SIZE>i; i++) { buff[i] = 0; }
39 */
40 /* now start adding each factor */
41 for (i=2; MAX_SIZE>i; i++)
42 {
43 /* process each prime number */
44 if (0 == buff[i])
45 {
46 /* have a prime! */
47 buff[i] = 1;
48 for (j=2*i; MAX_SIZE>j; j=j+i)
49 {
50 /* update each multiple ot include this prime factor */
51 buff[j] = buff[j] + 1;
52 } /* update each multiple ot include this prime factor */
53 } /* have a prime! */
54 } /* process each prime number */
55 } /* FUNCTION init */
56
57 int dump()
58 {
59 /* FUNCTION dump */
60 } /* FUNCTION dump */
61
62 int getInput()
63 {
64 /* FUNCTION getInput */
65 int dataReadFlag;
66
67 scanf(" %d ", &num);
68
69 dataReadFlag = (0 != num);
70 return (dataReadFlag);
71 } /* FUNCTION getInput */
72
73 void process()
74 {
75 /* FUNCTION process */
76 printf("%d : %d\n", num, buff[num]);
77 } /* FUNCTION process */
78
79 int main ()
80 {
81 /* main */
82 int moreToDo;
83
84 init();
85 moreToDo = getInput();
86 while (moreToDo)
87 {
88 /* while */
89 process();
90 moreToDo = getInput();
91 } /* while */
92
93 return EXIT_SUCCESS;
94 } /* main */
95