Returns a constexpr prime just under a twos power e.g. for 8, you get 251, which is the prime just below (1<<8) = 256. Very handy for hash tables.
40 {
41
42
43
44 switch(power)
45 {
46 case 0:
47 return 1;
48 case 1:
49 return 2;
50 case 2:
51 return (1ULL << 2) - 1;
52 case 3:
53 return (1ULL << 3) - 1;
54 case 4:
55 return (1ULL << 4) - 3;
56 case 5:
57 return (1ULL << 5) - 1;
58 case 6:
59 return (1ULL << 6) - 3;
60 case 7:
61 return (1ULL << 7) - 1;
62 case 8:
63 return (1ULL << 8) - 5;
64 case 9:
65 return (1ULL << 9) - 3;
66 case 10:
67 return (1ULL << 10) - 3;
68 case 11:
69 return (1ULL << 11) - 9;
70 case 12:
71 return (1ULL << 12) - 3;
72 case 13:
73 return (1ULL << 13) - 1;
74 case 14:
75 return (1ULL << 14) - 3;
76 case 15:
77 return (1ULL << 15) - 19;
78 case 16:
79 return (1ULL << 16) - 15;
80 case 17:
81 return (1ULL << 17) - 1;
82 case 18:
83 return (1ULL << 18) - 5;
84 case 19:
85 return (1ULL << 19) - 1;
86 case 20:
87 return (1ULL << 20) - 3;
88 case 21:
89 return (1ULL << 21) - 9;
90 case 22:
91 return (1ULL << 22) - 3;
92 case 23:
93 return (1ULL << 23) - 15;
94 case 24:
95 return (1ULL << 24) - 3;
96 case 25:
97 return (1ULL << 25) - 39;
98 case 26:
99 return (1ULL << 26) - 5;
100 case 27:
101 return (1ULL << 27) - 39;
102 case 28:
103 return (1ULL << 28) - 57;
104 case 29:
105 return (1ULL << 29) - 3;
106 case 30:
107 return (1ULL << 30) - 35;
108 case 31:
109 return (1ULL << 31) - 1;
110 case 32:
111 return (1ULL << 32) - 5;
112 case 33:
113 return (1ULL << 33) - 9;
114 case 34:
115 return (1ULL << 34) - 41;
116 case 35:
117 return (1ULL << 35) - 31;
118 case 36:
119 return (1ULL << 36) - 5;
120 case 37:
121 return (1ULL << 37) - 25;
122 case 38:
123 return (1ULL << 38) - 45;
124 case 39:
125 return (1ULL << 39) - 7;
126 case 40:
127 return (1ULL << 40) - 87;
128 case 41:
129 return (1ULL << 41) - 21;
130 case 42:
131 return (1ULL << 42) - 11;
132 case 43:
133 return (1ULL << 43) - 57;
134 case 44:
135 return (1ULL << 44) - 17;
136 case 45:
137 return (1ULL << 45) - 55;
138 case 46:
139 return (1ULL << 46) - 21;
140 case 47:
141 return (1ULL << 47) - 115;
142 case 48:
143 return (1ULL << 48) - 59;
144 case 49:
145 return (1ULL << 49) - 81;
146 case 50:
147 return (1ULL << 50) - 27;
148 case 51:
149 return (1ULL << 51) - 129;
150 case 52:
151 return (1ULL << 52) - 47;
152 case 53:
153 return (1ULL << 53) - 111;
154 case 54:
155 return (1ULL << 54) - 33;
156 case 55:
157 return (1ULL << 55) - 55;
158 case 56:
159 return (1ULL << 56) - 5;
160 case 57:
161 return (1ULL << 57) - 13;
162 case 58:
163 return (1ULL << 58) - 27;
164 case 59:
165 return (1ULL << 59) - 55;
166 case 60:
167 return (1ULL << 60) - 93;
168 case 61:
169 return (1ULL << 61) - 1;
170 case 62:
171 return (1ULL << 62) - 57;
172 case 63:
173 return (1ULL << 63) - 25;
174 case 64:
175 return (0xffffffffffffffffULL - 58);
176 default:
177 return 0;
178 }
179 }