#include<iostream>
#include <vector>
#include <iomanip>
using namespace std;
int print(int n, int t) {
for (unsigned long long i = pow(10, n - 1); i < pow(10, n); i++) {
if (i % t == 0)
return i;
}
return -1;
}
int main() {
int n, t;
cin >> n >> t;
cout << print(n ,t);
}
Hi, I have a method where it finds a whole number that is n digits long and divisible by t. It works correctly for almost all cases, except when n is large. One problematic example is when n = 18 and t = 8.
I printed out pow(10, n - 1) with set precision(18) and the number is 10^17. However, the answer I get back is 1569325056, which is only 10 digits.
I don't understand how I get a number less than 10^18, which should be the smallest number. Shouldn't an unsigned long long int be enough to hold the 10^18?