什么是最快的实施方式
template <typename T>
unsigned highest_decimal_digit(T x);
Run Code Online (Sandbox Code Playgroud)
(返回例如3表示356431,7表示71表示,9表示9表示)?
我能想到的最好的是:
......但也许有另一种方法.
笔记:
algorithm integer bit-manipulation modulus integer-arithmetic
在Project Euler问题中,我需要处理可能有数百个数字的数字.我需要对前9位进行一些计算.
我的问题是:确定100位整数的前N位数的最快方法是什么?模数/余数的前N位数很容易.对于第一个数字,我可以按模数应用模数100次,或者我可以将数字转换为字符串并截断,但它们都是线性时间.有没有更好的办法?