如何快速求 n 个数同余哪一个数?
查看原帖
如何快速求 n 个数同余哪一个数?
857626
_RainCappuccino_楼主2023/9/12 23:17

rt,只会暴力.

For(m, 2, max){
    memset(cnt, 0, sizeof cnt);
    int tot = 0;
    For(i, 1, n){
        if(cnt[a[i] % m] == 0) tot ++;
        cnt[a[i] % m] ++;
    }
    if(tot < ans){
        ans = tot;
        w = m;
    }
    if(ans == 1) break;
}
2023/9/12 23:17
加载中...