1
0
mirror of https://github.com/renbaoshuo/202401-programming-assignments.git synced 2024-11-27 02:25:37 +00:00
202401-programming-assignments/【实践课外】6.循环结构3/7-3 梅森数.c

33 lines
509 B
C

#include <stdio.h>
int main() {
int n, num = 2, count = 0;
scanf("%d", &n);
for (int i = 2; i <= n; i++) {
num *= 2;
int is_prime = 1;
for (int j = 2; j * j <= num - 1; j++) {
if ((num - 1) % j == 0) {
is_prime = 0;
break;
}
}
if (is_prime == 1) {
printf("%d\n", num - 1);
count++;
}
}
if (count == 0) {
printf("None\n");
}
return 0;
}