Project Euler #46: Goldbach's other conjecture

  • + 0 comments

    code in c:

    bool is_prime(int n){

    for (int i= 2; i<=sqrt(n); i++)  if(n%i == 0) return false;
    return true;
    

    } int rec(int s){

    int n = 1;
          int count = 0;
          while (s-2*n*n > 1) {
              int num = s-2*n*n;
              if(is_prime(num)==true) count++;
              n++;
          }
    return count;
    

    } int main() {

    int t;
    scanf("%d",&t);
    while (t--) {
        int n;
        scanf("%d",&n);
        printf("%d\n",rec(n));
    }
    return 0;
    

    }