Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <assert.h>
- #include <math.h>
- #define INPUT "input.txt"
- #define OUTPUT "output.txt"
- int sumOfDigits(int x) {
- int res = 0;
- do {
- res += (x % 10);
- x /= 10;
- } while(x);
- return res;
- }
- int findSol(unsigned long long n) {
- int x, min = -1;
- for(x = 0; x < 180; x++) {
- if((x*x + sumOfDigits(x)*x - n) == 0) {
- min = x;
- break;
- }
- }
- return min;
- }
- int main(int argc, char **argv) {
- FILE *file_in, *file_out;
- unsigned long long n;
- file_in = fopen(INPUT, "r");
- file_out = fopen(OUTPUT, "w");
- assert(fscanf(file_in, "%llu", &n) == 1);
- fprintf(file_out, "%d", findSol(n));
- fclose(file_in);
- fclose(file_out);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement