[ARC145D] Non Arithmetic Progression Set
james1BadCreeper · · 题解
upd: 感谢 \@Delov 的 Hack,现在已经更换为正确的构造方式,麻烦管理重审。
首先,
我们先抛开和为
这里先给出结论:将数写成三进制,当数的所有位都是
为什么呢?考虑
现在假定我们构造出来的集合可以表示为递增序列
假设我们的
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long i64;
int n, a[10005];
i64 m, s = 0;
int main(void) {
cin >> n >> m;
for (int p = 1; p <= n; ++p) {
int x = 0, i = p * 2;
for (int j = 0, z = 1; j < 16; ++j, z *= 3)
if ((i >> j) & 1) x += z;
a[p] = x; s += a[p];
}
int x = ((m - s) % n + n) % n;
for (int i = 1; i <= x; ++i) ++a[i], ++s;
i64 buf = (m - s) / n; s = 0;
for (int i = 1; i <= n; ++i) printf("%d ", a[i] + buf);
putchar('\n');
return 0;
}