Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <assert.h>
- #include <math.h>
- unsigned long long N;
- float X,min=9999999999.9;
- int somma(int x)
- {
- int s=0,log,i,p10=1;
- log=(int)(log10((double)x));
- for(i=0;i<=log;i++)
- {
- s+=(int)(floor( ((double)x) / ((double)p10) )) % 10;
- p10*=10;
- }
- return s;
- }
- int main() {
- FILE *fr, *fw;
- int sqr,x=-1,i;
- fr = fopen("input.txt", "r");
- fw = fopen("output.txt", "w");
- assert(1 == fscanf(fr, "%llu", &N));
- sqr=(int)floor(sqrt(N));
- for(i=0;i<=90;i++)
- {
- X=(sqrt(i*i+4*N)-i)/2.0;
- //fprintf(fw, "i:%d, somma(X):%d, X:%f, (int)X:%d, del:%d\n",i,somma(X),X,(int)X,i*i+4*N);
- //if(X==(int)X) fprintf(fw, "1ok\n");
- //if(somma(X)==i) fprintf(fw, "2ok\n");
- //if(X<min) fprintf(fw, "3ok\n");
- if((X==floor(X))&&(somma(X)==i))
- {
- if(X<min)
- {
- min=X;
- x=X;
- //fprintf(fw, "yep\n");
- }
- }
- }
- fprintf(fw, "%d\n", x);
- fclose(fr);
- fclose(fw);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement