Note that there are some explanatory texts on larger screens.

plurals
  1. POfmodl - Modulus in long double
    text
    copied!<pre><code>#include &lt;iostream&gt; #include &lt;cmath&gt; using namespace std; unsigned long long modExp(unsigned long long b, unsigned long long e, unsigned long long m) { unsigned long long remainder; unsigned long long x = 1; while (e != 0) { remainder = e % 2; e= e/2; // These lines if(remainder==1) x=(unsigned long long)fmodl(((long double)x*(long double)b),(long double)m); b=(unsigned long long)fmodl(((long double)b*(long double)b),(long double)m); } return x; } int main() { unsigned long long lastTen = 0,netSum=0; unsigned long long sec(unsigned long long,unsigned long long); for(int i=1;i&lt;1001;i++) { lastTen = modExp(i,i,10000000000); netSum += lastTen; netSum %= 10000000000; cout &lt;&lt; lastTen &lt;&lt; endl ; } cout &lt;&lt; netSum%10000000000 &lt;&lt; endl; cout &lt;&lt; sizeof(long double) &lt;&lt; endl; return 0; } </code></pre> <p>This is my program to compute the last ten digits of a sum of series. It uses Arithmetic Exponentiation technique to compute the last 10 digits. It works well for 10^9. But when I go for a 10^10 it collapses. </p> <p>So in order to use the higher size data types I have converted the number to be multiplied to long double and multiplied them(which would again yield long double) so if we take modulus on this number we would get the answer correctly. But I did not get the right answer again it causes the same wrong answer. </p> <p>My thought to make such thing is like this</p> <ul> <li>an unsigned long long is 8 bytes, since I am moding i would get a large number as a 10 digit number so multiplying 2, ten digit numbers would not fit in unsigned long long so it would cycle in unsigned long long</li> <li>so for the above point I convert the unsigned long long to long double(which is 12 bytes) and since it has large space it is large enough to fit a 20 digit product of 2 ten digit numbers</li> </ul> <p>Can any one say what is the flaw in this logic?? </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload