fork(3) download
  1. #include <stdio.h>
  2.  
  3. c;s;m;M;f(n){while(s-n){while(s<n)s+=++M;c++;if(s==n)return c;while(s>n)s-=++m;c++;}return c;}
  4.  
  5. int main(void)
  6. {
  7. int n = 8;
  8. printf("%d %d",n,f(n));
  9. return 0;
  10. }
  11.  
Success #stdin #stdout 0s 10304KB
stdin
Standard input is empty
stdout
8 10