【发布时间】:2020-04-10 19:44:17
【问题描述】:
**There is a structure in my program**
#include<bits/stdc++.h>
using namespace std;
#define N 1000005
#define MAX 1e18
// Vector to store powers greater than 3
vector<long long int> powers;
// vector to store perfect squares
vector<long long int> squares;
void computation()
{
unordered_map<long long int,long long int> mp;
unordered_map<long long int,long long int> ms;
squares.push_back(1);
ms[1]=1;
for (long long int i = 2; i <N; i++)
{
// pushing squares
squares.push_back(i * i);
ms[i*i]=1;
if (ms[i]==1)
continue;
long long int temp = i;
// run loop until some
// power of current number
// doesn't exceed MAX
while (i * i <= MAX / temp)
{
temp *= (i * i);
if(mp[temp]==0){
powers.push_back(temp);
mp[temp]=1;
}
}
}
sort(powers.begin(),powers.end());
sort(squares.begin(),squares.end());
}
在计算函数调用后的主函数中,任何操作都会产生 sig 错误
int main(){
computation();
return 0;
}
如何使用 map 正确重写? 对不起,如果这个问题已经被问过了,我在看的时候无法理解。
【问题讨论】:
-
即使我使用 unsigned long long int 错误仍然存在
标签: algorithm dictionary runtime-error c++14 sigabrt