Y可以整除的最大数字 [英] Greatest number divisible by Y
问题描述
我正在尝试为X设计一个编译时常量,其中X是
最大数,它满足以下两个条件:
(1)X< = DESIGNATED_MAX_VALUE
(2)X%Y == 0
我会尝试用示例代码解释:< br $>
#define MAX_DIVISIBLE(max,divisor)/ * Something * /
int main(void)
{
unsigned long max = -1;
unsigned long max_divisible_by_10 = MAX_DIVISIBLE(max,10);
}
在unsigned long有32个值位的系统上,变量应该是
得到以下值:
max == 4294967295
max_divisible_by_10 == 1000000000
有没有人写过这样的宏?如果没有,有人可以给
指针吗?
-
Frederick Gotham
I''m trying to devise a compile-time constant for X, where X is the
greatest number which satisfies both the following criteria:
(1) X <= DESIGNATED_MAX_VALUE
(2) X % Y == 0
I''ll try to explain with example code:
#define MAX_DIVISIBLE(max,divisor) /* Something */
int main(void)
{
unsigned long max = -1;
unsigned long max_divisible_by_10 = MAX_DIVISIBLE(max,10);
}
On a system where unsigned long has 32 value bits, the variables should
get the following values:
max == 4294967295
max_divisible_by_10 == 1000000000
Has anyone ever written such a macro? If not, can anyone please give
pointers?
--
Frederick Gotham
推荐答案
Frederick Gotham写道:
Frederick Gotham wrote:
我正在尝试为X设计一个编译时常量,其中X是最大的数字满足以下两个标准:
(1)X< = DESIGNATED_MAX_VALUE
(2)X%Y == 0
#define MD(max,divisor)((max) - (max)%(除数))
max == 4294967295
max_divisible_by_10 == 1000000000
I''m trying to devise a compile-time constant for X, where X is the
greatest number which satisfies both the following criteria:
(1) X <= DESIGNATED_MAX_VALUE
(2) X % Y == 0
#define MD(max, divisor) ( (max) - (max) % (divisor) )
max == 4294967295
max_divisible_by_10 == 1000000000
应该是4294967290,除非你使用了一些新的含义
''divisible''你不是在告诉我们
Should be 4294967290, unless you are using some new meaning
of ''divisible'' that you aren''t telling us
Frederick Gotham说:
Frederick Gotham said:
我正在尝试为X设计一个编译时常量,其中X是最大的满足以下两个标准的数字:
(1)X< = DESIGNATED_MAX_VALUE
(2)X%Y == 0
I''m trying to devise a compile-time constant for X, where X is the
greatest number which satisfies both the following criteria:
(1) X <= DESIGNATED_MAX_VALUE
(2) X % Y == 0
#define MAX_DIVISIBLE(m, d)(m / d)* d
-
Richard Heathfield
Usenet是一个奇怪的地方 - dmr 29/7/1999
http://www.cpax.org.uk
电子邮件:rjh在上面的域名(但显然放弃了www)
#define MAX_DIVISIBLE(m, d) (m / d) * d
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
老狼发布:
< br>
Old Wolf posted:
max == 4294967295
max_divisible_by_10 == 1000000000
max == 4294967295
max_divisible_by_10 == 1000000000
应该是4294967290 ,除非你使用了一些新的含义可分割的你并没有告诉我们
Should be 4294967290, unless you are using some new meaning
of ''divisible'' that you aren''t telling us
(我建议使用单空格字体来阅读这个。)
你是对的,我措辞错误。
我会再试一次。 (我会尝试从输入,流程,
和输出的角度来考虑它。)
以下是输入:
max_value:4294967295
除数:10
这里是所需的输出:
1000000000
我认为我正在寻找的输出是满足以下两个标准的最大数字:
:
(1)输出< = max_value
(2)输出的Log-base-divisor是一个精确的整数。
以下是一些示例输入和输出:
输入:237509275
10
输出:100000000
输入: 98722
10
输出:10000
输入:9270720
10
输出:1000000
输入:45
10
输出:10
输入:4648
10
输出:1000
-
Frederick Gotham
(I suggest using a mono-space font for reading this.)
You''re correct, I worded it wrongly.
I''ll try again. (I''ll try to think of it in terms of inputs, processes,
and outputs).
Here are the inputs:
max_value: 4294967295
divisor: 10
Here''s the desired output:
1000000000
I think the output I''m looking for is the greatest number which satisfies
the two following criteria:
(1) output <= max_value
(2) Log-base-divisor of output is an exact integer.
Here are some sample inputs and outputs:
Inputs: 237509275
10
Output: 100000000
Inputs: 98722
10
Output: 10000
Inputs: 9270720
10
Output: 1000000
Inputs: 45
10
Output: 10
Inputs: 4648
10
Output: 1000
--
Frederick Gotham
这篇关于Y可以整除的最大数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!