For the below code:
int digsum(ll num) { //function to calculate sum of digits
if (num < 0)
num = abs(num);
int ans = 0;
while (num != 0) {
ans = ans + num % 10;
num = num / 10;
}
return ans;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int a, b, c, cnt = 0;
long long x;
cin >> a >> b >> c;
for (int i = 0; i <= 72; i++) {
x = (b * (pow(i, a))) + c;
if (i == digsum(x) && x < mod) {
cout << x << " ";
}
}
return 0;
}
In the case a,b,c = 3,2,8
respectively and i=19;
pow(19,3)
is supposed to calculate 19^3 but when I replace pow
by (19x19x19), this specific case is getting satisfied, where as that wasn't the case with the pow
function.
Can someone explain what the problem is?