Last active
October 18, 2018 11:15
-
-
Save Ujjwal0501/c91b8be44e9b3bb2f38e45744fe41481 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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); | |
} | |
} |
Due to a large number of recursive calls, segmentation fault occurs
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
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