I’ve been getting the SIGABRT error, and I am not able to think of any reason why this is happening.
I’ve set all of the variables as uint64_t
, and assigned a vector that stores all the values of fusc for n
numbers. Within the loop, I also check for the max value of fusc and store it in max_fusc
. Would anyone take a look? This1 is the link to the question.
I’ve even tried other widths, like 16 and 32, and even unsigned long datatype. Still no luck.
My code:
#include <vector>
#include <iostream>
#include <string>
#include <algorithm>
int main()
{
uint64_t n;
std::cin >> n;
std::vector<uint64_t> reg;
reg.reserve(n+1);
reg.push_back(0);
reg.push_back(1);
uint64_t max_fusc = n ? 1 : 0;
for(uint64_t i = 2; i <= n; i++) {
reg.push_back(i%2 == 0 ? reg[i/2] : reg[i/2] + reg[i/2 + 1]);
max_fusc = std::max(max_fusc, reg.back());
}
std::cout << max_fusc << std::endl;
}
created
last reply
- 1
reply
- 560
views
- 2
users
- 1
link