-
Notifications
You must be signed in to change notification settings - Fork 1
/
enneagon.cpp
55 lines (47 loc) · 1.04 KB
/
enneagon.cpp
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
#include <stdio.h>
#include <stdlib.h>
// https://www.zhihu.com/question/46235037
/**
* N芒星N个顶点,如果能找到一个数值k(k>1),每次跳过k个顶点,如果N次之后能将所有的顶点遍历,则判断可以一笔画出.
* */
bool EnneagonTest(unsigned int n)
{
if (n < 4)
{
return false;
}
bool rst = false;
bool *arr = new bool[n];
printf("Enneagon %d:", n);
for (unsigned int k = 2; k <= n / 2; k++)
{
memset(arr, 0, n * sizeof(bool));
unsigned int t = 0;
for (unsigned int i = 0; i < n; i++)
{
arr[t] = true;
t = (t + k) % n;
}
bool can = true;
for (unsigned int i = 0; i < n; i++)
{
if (!arr[i])
{
can = false;
break;
}
}
if (can)
{
printf("%d ", k);
rst = true;
}
}
if (!rst)
{
printf("Can not");
}
printf("\r\n");
delete[] arr;
return rst;
}