【发布时间】:2014-01-20 14:29:01
【问题描述】:
我编写了以下C代码来找出一个大数的最大引物因子,并且我的程序在运行时一直执行。我尝试通过分配iBigNum来调试它,范围为2^32-1,然后它工作。
LONG64 iBigNum = 600851475143,iCurr=0,iLarge=0;
//600851475143
/*4294967295
4000000000
*/iCurr = iBigNum-1;
while(iCurr > 0 )
{
if(iBigNum % iCurr == 0){
iLarge=iCurr;
break;
}
iCurr--;
}
MsgPrintf(TEXT("CustomPrint"),TEXT("%d"),iLarge);
之间,LONG64 定义为basetsd.h
//
// The following types are guaranteed to be signed and 64 bits wide.
//
typedef __int64 LONG64, *PLONG64;
我在 Intel Core 2 Duo CPU 上运行代码,运行频率为 3.16GHz,内存为 4 GB。这是预期的行为吗?有人可以指出我的方向吗? 谢谢
【问题讨论】:
-
注意:"%d" 可能无法与
iBigNum一起正常工作。 -
@chux 谢谢,改成“%ld”
-
建议
"%I64d"_ _int64 或stackoverflow.com/questions/3068088/…
标签: c winapi long-integer