I got a homework which goes through a compiler which checks if all is correct but it keeps giving result : "time limit exceeded" , the application works as it should in normal C++ compiler but I have to send the code to Themis which doesn't accept it due to "time limit exceeded"
Task : Input: In the first input line is given the integer t (1 ≤ t ≤ 100000) specifying the number of tests. Each test is given by three integers: a, b, m as defined above (1 ≤ a ≤ 10^9, 0 ≤ b ≤ 10^9, 1 ≤ m ≤ 10^6).
Output:
T lines should be printed. In each line, the answer to the query: (a^b)% m
.
example of input data:
2
3 2 10
the correct answer is : 9
One friend told me to change cout to printf which might result in faster runtime but I'm not sure how to do it.
My code
#include <iostream>
using namespace std;
int main()
{
int t;
cin>>t;
for (int i=0; i<t; ++i)
{
int a,b,m;
long long int x,wynik=1;
cin>>a>>b>>m;
x=(long long int) a;
do
{
x%=(long long int)m;
if (b&1) {
wynik*=x;
wynik%=(long long int)m;
}
x*=x;
} while (b>>=1);
cout <<wynik<<endl;;
}
return 0;
}