社区讨论

求助 GDB调试出现Segmentation fault错误

P2152[SDOI2009] SuperGCD参与者 4已保存回复 8

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
8 条
当前快照
1 份
快照标识符
@mi6y5msa
此快照首次捕获于
2025/11/20 12:44
4 个月前
此快照最后确认于
2025/11/20 12:44
4 个月前
查看原帖
粘代码
CPP
#include<algorithm>
#include <cstring>
using namespace std;

const int SIZE = 1e5;
struct hugeint
{
    int len;
    long long num[1000000];
} e, ans;

void times(hugeint a, hugeint b)
{ 
    hugeint con;//容器的英文:container;
    con.len = 0;
    memset(con.num, 0, sizeof(con.num));
    for (int i = 1; i <= a.len; ++i)
        for (int j = 1; j <= b.len; ++j)
            con.num[i + j - 1] += a.num[i] * b.num[j];
    for (int i = 1; i <= a.len + b.len - 1; ++i)
    {
        ans.num[i + 1] += ans.num[i] / SIZE;
        ans.num[i] %= SIZE;
    }
    if (con.num[a.len + b.len] != 0) con.len = a.len + b.len;
    else con.len = a.len + b.len - 1;
    ans = con;
    return;
}

void qhy(int xmm)
{
    if (xmm == 0) return;
    if (xmm <= 1) return;
    if (xmm % 2 == 1) times(ans, e);
    qhy(xmm / 2);
    times(ans, ans);
}

int main()
{
    int n;
    scanf("%d", &n);
    e.len = 1;
    e.num[1] = 2;
    ans.len = 1;
    ans.num[1] = 1;
    qhy(n);
    printf("%d\n", ans.len);
    ans.num[1] -= 1;
    for (int i = 100; i >= 1; ++i)
    {
        int k = ans.num[i], x = 0;
        while (k != 0)
        {
            x++;
            k /= 10;
        }
        x = 5 - x;
        if (x == 5) x--;
        for (int j = 1; j <= x; ++j) printf("0");
        printf("%d", ans.num[i]);
    }
    printf("\n");
    return 0;
}
为什么调试到qhy(int xmm)函数的时候会报错啊 是不是内存太大了?

回复

8 条回复,欢迎继续交流。

正在加载回复...