How to convert very long numbers (more specifically long double) to integers


I was solving this question where a very large number 16^123 is involved. As I have a habit of ‘seeing’ everything as programming problems, I realized that if I can just calculate 16^123 which is 22142024630120207368183773162315510695991025691578204136484229989042903038958701481563926559866088068
690875167586818560952715154383806383816600300027904 and then take its modulus by 257, I get the answer. But the data type required to store such a huge number is probably long double and any data type involving floating points cannot be used in modulo arithmetic.

So, I was wondering if there was a way that such huge numbers can be converted to integers( or numbers without decimals) and still modulo arithmetic be used on it?



Firstly i don’t think that long double or any other data type in c++ can store the actual value of 16^123, but there are many methods to calculate (say 16^123 mod 257) without calculating the actual value of 16^123

Check this out

But if the use the iomanip header and set the cout.setf(ios::fixed) flag, the number is displayed correctly.

Yes,but you cannot store it in a non-floating point variable to operate modulus operation on it.