标签:map fir ret printf 数列 tin int i++ eof
#include <stdio.h>
int fill(char *map,int *primes) {
for (int i = 2; i < 1001; i++) {
map[i] = 1;
for (int j = 2; j < i; j++) {
if (i % j == 0) {
map[i] = 0;
break;
}
}
}
int j = 0;
for (int i = 0; i < 1001; i++) {
if (map[i]) {
primes[j++] = i;
}
}
primes[j] = 10000;
return 0;
}
int f(int n, int m) {
static char map[1001] = {0};
static int primes[200] = {0};
static int firstin = 1;
if (firstin) {
fill(map,primes);
firstin = 0;
}
int count = 0;
for ( int i = 0; primes[i] <= m; i++) {
for (int delta = 1; (n-1)*delta + primes[i] <= m; delta++) {
int it_is = 1;
for (int j = 0; j < n; j++) {
if (map[primes[i] + j*delta] == 0) {
it_is = 0;
break;
}
}
if (it_is) {
count++;
//printf("delta = %d,", delta);
//printf("prime_num = %d,", primes[i]);
//printf("m = %d\n", m);
}
if (n == 1) {
break;
}
}
}
return count;
}
int main()
{
int n,m,t;
while(scanf("%d%d",&m,&n)!=EOF)
{
t=f(m,n);
printf("%d\n",t);
}
return 0;
}
标签:map fir ret printf 数列 tin int i++ eof
原文地址:https://www.cnblogs.com/cy846586184/p/12269764.html