Kodewick
Start learning →
Basic←→0 / 50

Perfect square puzzle

#022Basicis_square(x + 100) && is_square(x + 268)6 min

A classic puzzle: for a whole number x, x + 100 is a perfect square and x + 268 is too. What is x? Find every answer from 0 to 10000, smallest first, one per line. For example 21: 21 + 100 = 121 = 11², 21 + 268 = 289 = 17². is_square(v) is already written and returns true if v is a perfect square.

Should show
21
261
1581
main.c
#include <stdio.h>
#include <math.h>
#include <stdbool.h>

bool is_square(int v) {
    int r = (int)sqrt(v);
    return r * r == v;
}

int main(void) {
    for (int x = 0; x <= 10000; x++) {
        // your code here: if x + 100 and x + 268 are both squares, show x
    }
    return 0;
}
Ctrl + Enter runs too
Result

Run tries the examples. When they look right, Submit.