96 std::string num2 = val.
GetNum(), num1 =
num;;
97 reverse(num1.begin(), num1.end());
98 reverse(num2.begin(), num2.end());
99 int carry = 0, n = std::max(num1.length(), num2.length()) + 1;
100 num1 += std::string(n - num1.length(),
'0');
101 num2 += std::string(n - num2.length(),
'0');
102 std::string ans = std::string(n,
'0');
103 for (
int i = 0; i < n; i++) {
104 ans[i] += num1[i] + num2[i] - 2 *
'0';
110 if (ans[n - 1] ==
'0') ans.erase(n - 1, 1);
111 reverse(ans.begin(), ans.end());
123 std::string num1 =
num, num2 = val.
GetNum();
127 bool isMunus = val > *
this;
130 reverse(num1.begin(), num1.end());
131 reverse(num2.begin(), num2.end());
132 std::string ans = std::string(num1.length(),
'0');
133 num2 += std::string(num1.length() - num2.length(),
'0');
134 for (
int i = 0; i < num1.length(); i++) {
135 ans[i] += num1[i] - num2[i];
141 reverse(ans.begin(), ans.end());
143 while (ans[i] ==
'0') i++;
144 return large((isMunus ?
"-" :
"") + ans.substr(i));
148 std::string num1 =
num, num2 = val.
GetNum();
150 if (num1 ==
"0" || num2 ==
"0")
152 if (num2.length() > 1) {
153 std::vector<large> nums;
154 for (
int i = num2.length() - 1; i >= 0; i--) {
155 nums.push_back(*
this *
large(num2.substr(i, 1)));
156 if (nums[num2.length() - 1 - i] !=
large(0))
157 nums[num2.length() - 1 - i] =
large(nums[num2.length() - 1 - i].GetNum() + std::string(num2.length() - 1 - i,
'0'));
159 for (
int i = 0; i < nums.size(); i++) ans += nums[i];
162 for (
int i = 0; i < atoi(num2.c_str()); i++)
169 std::string num1 =
num, num2 = std::to_string(val), ans =
"";
171 long long tmp, i = 1;
172 for (; (i < num1.length()) && (tmp = atoi(num1.substr(0, i).c_str()), tmp < val); i++) {}
173 tmp = atoi(num1.substr(0, i).c_str());
178 ans += std::to_string(tmp / val);
181 while (num1.length() > 0) {
182 if (tmp == 0 && num1 == std::string(num1.length(),
'0'))
183 return large(ans + num1);
186 tmp += atoi(num1.substr(0, 1).c_str());
188 ans += std::to_string(tmp / val);
191 ans += std::to_string(atoi(num1.substr(0, 1).c_str()) / val);
192 tmp = atoi(num1.substr(0, 1).c_str()) % val;
197 return large((isMinus ?
"-" :
"") + ans);