我有一个需要使用变量的问题
1 <= N <= 10 ^ 80
其中一个测试用例具有一个值:
3141592653589793238462643383279502884197169399375
并且使用unsigned long long int,程序将该最大值视为:
18446744073709551615
显然,我需要存储一个大于该值的值。
我该如何解决这个问题?
#include <iostream>
using namespace std;
int main()
{
unsigned long long int N;
cin >> N;
unsigned long long int Z;
int result = 0;
unsigned long long int broj = N;
while (N > 0) {
Z += N % 10;
N /= 10;
}
while (Z % 9 != 0) {
Z += broj;
result++;
}
cout << Z;
return 0;
}
template<class Type>
class BigInt
{
typedef typename Type BT;
protected:
std::vector<Type> value_;
};
换句话说,您只是将大数字分开,并将每个部分记录到向量中。