Skip to content

Instantly share code, notes, and snippets.

@Ujjwal0501
Last active October 18, 2018 11:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ujjwal0501/c91b8be44e9b3bb2f38e45744fe41481 to your computer and use it in GitHub Desktop.
Save Ujjwal0501/c91b8be44e9b3bb2f38e45744fe41481 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
int level = 0;
int digitsum(long long int n) {
int result = 0;
while (n) {
result += n%10;
n /= 10;
}
return result;
}
void func(long long int n, long long int d, long long int *min, long long int *count) {
if (level < 13) {
level++;
if (n < *min) {
*min = n;
if (*count > level) *count = level;
}
func(n+d, d, min, count);
func(digitsum(n), d, min, count);
}
level --;
return ;
}
int main(void) {
int t;
cin >> t;
while (t--) {
long long int n, d, min = 100000, count = 10000000;
cin >> n >> d;
func(n, d, &min, &count);
}
}
@Ujjwal0501
Copy link
Author

Starting program: /media/ujjwal/DataDisk/krow/Myprojects/GitHub/Offline/mindsum
INPUT - 1 2 3

Program received signal SIGSEGV, Segmentation fault.
0x000055555555499a in func (n=2, d=3, min=0x7fffffffddf8, count=0x7fffffffde00) at mindsum.cpp:22

@Ujjwal0501
Copy link
Author

Due to a large number of recursive calls, segmentation fault occurs

@Ujjwal0501
Copy link
Author

The stack is normally limited by a resource limit. You can see what the default settings are on your installation using
ulimit -a
See here how to change the stack size in a program.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment