我正在寻找一种有效的算法来解决以下问题.让d(n)
表示正除数的数n
,其中n
为正整数.我们给了一些 1 <= a <= b <= 10^18
,任务是找到最大值的d
段[a..b]
和(可能我们需要更复杂的算法,这部分)找到最大化值的数字d
.
前段时间我在免费访问中找到了以下代码:http://ideone.com/qvxPj
unsigned long long n, res;
int p, primes[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 51, 53, 59, 61, 67, 71};
unsigned long long mul(unsigned long long a, unsigned long long b){
unsigned long long res = 0;
while (b){
if (b & 1LL) res = …
Run Code Online (Sandbox Code Playgroud) 在C++命令中是真的吗?
n&1
更快,使用更少的内存
n%2?
(其中n是int类型)
更全局,有没有办法比使用%运算符更快地找到模2的整数残差?提前致谢.