处理大整数 [英] Dealing with a large integer
问题描述
大家好
这个格式有一个大整数
x1 * 256 ^ 5 + x2 * 256 ^ 4 + x3 * 256 ^ 3 + x4 * 256 ^ 2 + x5 * 256 + x6
现在我必须把它转换成这种格式
y1 * 900 ^ 4 + y2 * 900 ^ 3 + y3 * 900 ^ 2 + y4 * 900 + y5
x1-x5给出。我必须从中得到y1-y4。
怎么能我在32位电脑上这样做了吗?
很抱歉我的英语很差。
谢谢。
我有一个这种格式的大整数
x1 * 256 ^ 5 + x2 * 256 ^ 4 + x3 * 256 ^ 3 + x4 * 256 ^ 2 + x5 * 256 + x6
现在我必须把它转换成这种格式
y1 * 900 ^ 4 + y2 * 900 ^ 3 + y3 * 900 ^ 2 + y4 * 900 + y5
x1-x5。我必须从中获得y1-y4。
如何在我的32位PC上执行此操作?
抱歉我的英语很差。
使用支持大数字的语言,或者找个自己的图书馆
这适合你。
Igmar
yong写道:我有一个这种格式的大整数
x1 * 256 ^ 5 + x2 * 256 ^ 4 + x3 * 256 ^ 3 + x4 * 256 ^ 2 + x5 * 256 + x6
现在我必须把它转换成这种格式
y1 * 900给出了x1-x5 ^ 4 + y2 * 900 ^ 3 + y3 * 900 ^ 2 + y4 * 900 + y5
>我怎么能在我的32位PC上做到这一点?
很抱歉我的英语很差。
你可以试着想象一下modulo算术并使用
32位整数完成,但由于你要发布到comp.lang.c,你的机器
应该实现double。 ;在IEEE浮点数中,双精度数具有52 b / b $ b b位尾数,这足以容纳256 ^ 6和900 ^ 5。所以
只计算
double f = x [1];
for(i = 2; i< = 6 ; i ++)
f = f * 256 + x [i];
for(i = 5; y> = 1; y--){
y [i] = f%900;
f / = 900;
}
< blockquote> ge**********@gmail.com 写道:
[...]
double f = ...
[...] y [i] = f%900;
n869:6.5.5乘法运算符
[...]
约束
2 [... ]%运算符的操作数应具有整数类型。
Hi all
I have an large integer in this format
x1*256^5 + x2*256^4 + x3*256^3 + x4*256^2 + x5*256 + x6
now I must convert it to this format
y1*900^4 + y2*900^3 + y3*900^2 + y4*900 + y5
x1-x5 is given.I must get y1-y4 from it.
How can I do this on my 32bit PC?
Sorry for that my English is poor.
Thanks.
I have an large integer in this format
x1*256^5 + x2*256^4 + x3*256^3 + x4*256^2 + x5*256 + x6
now I must convert it to this format
y1*900^4 + y2*900^3 + y3*900^2 + y4*900 + y5
x1-x5 is given.I must get y1-y4 from it.
How can I do this on my 32bit PC?
Sorry for that my English is poor.
Use a language that has big numbers support, or find yourself a library
that does it for you.
Igmar
yong wrote:I have an large integer in this format
x1*256^5 + x2*256^4 + x3*256^3 + x4*256^2 + x5*256 + x6
now I must convert it to this format
y1*900^4 + y2*900^3 + y3*900^2 + y4*900 + y5
x1-x5 is given.I must get y1-y4 from it.
How can I do this on my 32bit PC?
Sorry for that my English is poor.
You can try to be fancy about modulo arithmetic and get it done with
32-bit integers, but since you are posting to comp.lang.c, your machine
ought to implement "double." In IEEE floating point, doubles have a 52
bit mantissa, which is big enough to hold both 256^6 and 900^5. So
just compute
double f = x[1];
for (i = 2; i <= 6; i++)
f = f * 256 + x[i];
for (i = 5; y >= 1; y--) {
y[i] = f % 900;
f /= 900;
}
ge**********@gmail.com wrote:
[...]double f = ... [ ... ] y[i] = f % 900;
n869: 6.5.5 Multiplicative operators
[ ...]
Constraints
2 [...] The operands of the % operator shall have integer type.
这篇关于处理大整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!