-
Notifications
You must be signed in to change notification settings - Fork 1
/
queue_down_to_zero2.c
58 lines (48 loc) · 913 Bytes
/
queue_down_to_zero2.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
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int queue[100000000];
int head, tail;
int go2zero(int num)
{
int i;
int ret = 0;
int cur;
head = tail = 0;
queue[head++] = num;
while (1) {
int old_head = head;
while (tail < old_head) {
cur = queue[tail++];
if (cur == 0)
goto FINISH;
for (i = 2; i <= (int)sqrt(cur); i++) {
if ((cur % i) == 0) {
queue[head++] = (int)cur/i;
}
}
queue[head++] = cur - 1;
}
ret++;
}
FINISH:
return ret;
}
int main(void)
{
int count, num;
int i;
scanf("%d", &count);
for (; count > 0; count--) {
scanf("%d", &num);
printf("%d\n", go2zero(num));
}
/* printf("->%d\n", go2zero(0)); */
/* printf("->%d\n", go2zero(5)); */
/* printf("->%d\n", go2zero(7)); */
/* printf("->%d\n", go2zero(94)); */
/* printf("->%d\n", go2zero(7273)); */
//printf("->%d\n", go2zero(225604));
return 0;
}