I was just solving some problems at Euler when I came across a simple problem, no. 16, and I wrote a simple program.
using namespace std;
unsigned long long num = pow(2,15);
rem = num%10;
cout<<"the sum of digits is "<<sum;
I don’t know why but this code is taking a lot more time than expected. How to optimize it? Many of my programs take a lot more time to complete the execution than expected…
is your problem.
You are dividing !num by 10;
The test should also be < 1
while(num/10 > 0)