题目大意: 给定 L, R,令 \(S[L,R]_{x}\) 表示区间 \([L,R]\)内 x
的倍数组成的集合,形式化的,我们有\(S[L,R]_{x}
= {d|L ≤ d ≤ R,
x|d}\)。定义一个集合的权值为这个集合中所有元素之和。那么,能否求出最小的
x,使得 \(S
[L,R]_x\)有非空子集的权值和为 K 呢?虽然小 P
喜欢数学,但数学似乎并不喜欢他,所以他并不会这个问题。请你帮助小 P
解决他的问题。若无解,请输出 No Solution
#include<bits/stdc++.h> #define int long long #define ll long long usingnamespace std;
constint N = 1e4 + 66;
inline ll read() { ll s(0), w(1); char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') w = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar(); return s * w; }
inlinevoidput(ll x) { if (! x) putchar('0'); if (x < 0) putchar('-'), x = -x; intnum(0); char c[66]; while (x) c[++ num] = x % 10 + 48, x /= 10; while (num) putchar(c[num --]); return (void)(putchar('\n')); }
inlinevoidyhm_func() { int L, R, K, cnt(0), ans = (1ll << 60), x, i, j, sum; L = read(), R = read(), K = read(); x = K, -- L; while (x % 2 == 0) x /= 2, ++ cnt;
for (i = 1, j = 0; i <= L; i = j + 1) { int l = L / i, r = R / i; j = min(L / l, R / r); if (r - l - 1 > cnt || r - l <= 0) continue; sum = K / (1ll << (r - l - 1)) * 2; if (sum % (r - l)) continue; x = sum / (r - l); if (x % (l + r + 1)) continue; x /= (l + r + 1); if (l == L / x && r == R / x) ans = min(ans, x); }
for (i = L + 1, j = 0; i <= R; i = j + 1) { int l = 0, r = R / i; j = R / r; if (r - l - 1 > cnt || r - l <= 0) continue; sum = K / (1ll << (r - l - 1)) * 2; if (sum % (r - l)) continue; x = sum / (r - l); if (x % (l + r + 1)) continue; x /= (l + r + 1); if (l == L / x && r == R / x) ans = min(ans, x); }