Exemplo n.º 1
0
int main () {
	int i, j, a, b, n;
	int a_max, b_max, n_max;

	gen_primes (LIMIT * LIMIT);

	for (i = LIMIT; i >= 0; i--) {
		if (seive[i] == PRIME) b = i;
		else continue;

		for (j = LIMIT; j >= -LIMIT; j--) {
			if (1 + j + b < 0) continue;
			if (seive[1 + j + b] == PRIME) a = j;
			else continue;

			for (n = 0;
					(n * n + a * n + b) > 0 && seive[n * n + a * n + b] == PRIME;
					n++)
				;

			if (n_max < n) {
				a_max = a;
				b_max = b;
				n_max = n;
			}
		}
	}

	printf ("a : %d, b : %d, a * b : %d\n", a_max, b_max, a_max*b_max);
	return 0;
}
Exemplo n.º 2
0
int main(void) {
  gen_primes();
  gen_dp();

  for (int i = 0; i <= MAX_MAG; i++) {
    for (int j = 0; j <= MAX_SUM; j++) {
      for (int k = 0; k <= MAX_SQ_SUM; k++) {
        if (dp[i][j][k]) {
          sq_sum_start[i][j] = k;
          break;
        }
      }
      for (int k = MAX_SQ_SUM; k >= 0; k--) {
        if (dp[i][j][k]) {
          sq_sum_end[i][j] = k;
          break;
        }
      }
    }
  }

  int cas;
  scanf("%d", &cas);
  while (cas--) {
    long long a, b;
    scanf("%lld %lld", &a, &b);
    printf("%lld\n", feeling_lucky(b) - feeling_lucky(a - 1));
  }
  return 0;
}
Exemplo n.º 3
0
int main (void) {
    int i, j, k, n, pos, p_len;
    int p[MAX_LENGTH];
    int base, circular;
    int total = 0;

    gen_primes ();
    for (i = 0; i < PRIME_COUNT; i++) {
        circular = true;
        p_len = log10 (prime[i]) + 1;
        get_digits (prime[i], &p[0], p_len);

        for (j = 1; j < p_len; j++) { /* form a new no. from a new start pos */
            base = pow (10, p_len - 1);
            pos = j;
            n = 0; k = 0;
            do {
                if (pos >= p_len) pos = 0;
                n += p[pos++] * base;
                base /= 10;
            } while (k++ < p_len);
            /* printf ("%d\n", n);  */
            if (!bsearch (&n, &prime[0], PRIME_COUNT, (int) sizeof (int), &compare))
                circular = false;
        }
        /* printf ("%d,", prime[i]);  */
        if (circular) {
            printf ("%d\n", prime[i]);
            total++;
        }
    }
    printf ("total=%d\n", total);
}
Exemplo n.º 4
0
int main() {
  int N;
  gen_primes();
  scanf("%d", &N);
  happy(N);
  return 0;
}
Exemplo n.º 5
0
int main(){
    int initial_num, final_num;
    int *ARR;
    
    int limit = int(ceil(sqrt(M)));
    ARR       = (int*)malloc(limit*sizeof(int));
    int count_d = store_divisors(ARR, limit);
    
    gen_primes(ARR, count_d);
    std::cout << std::endl;
}
Exemplo n.º 6
0
int main() {
  int T;
  scanf("%d", &T);
  gen_primes(1000009);
  memset(vis, 0, sizeof(vis));
  for(int kase = 1; kase <= T; kase++) {
    int n;
    scanf("%d", &n);
    printf("Case %d: %.10lf\n", kase, dp(n));
  }
  return 0;
}
Exemplo n.º 7
0
int main(int argc, char** argv) {
    gen_primes();
    gen_table();

    int cases = 0;
    scanf("%d", &cases);
    for (int i = 0; i < cases; ++i) {
        long long a, b;
        scanf("%lld %lld", &a, &b);
        printf("%lld\n", count_lucky(b) - count_lucky(a-1));
    }
    return 0;
}