#include #include
using namespace std;
long long fast_exp(int base, int exp) {
long long MOD=1000000007;
long long res=1;
while(exp>0) {
if(exp%2==1) res=(resbase)%MOD;
base=(basebase)%MOD;
exp/=2;
}
cout<< res%MOD<<endl;
}
main()
{
int t,base=2,exp;
cin>>t;
while(t–)
{
cin>>exp;
fast_exp(base,exp);
}
You can use in-built sort function of C++.(It can save a lot of time typing)
#include<iostream>
#include<algorithms>
using namespace std;
int main(){
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++) cin>>a[i];
sort(a,a+n);
return 0;
}
okay next, i feel your solution is correct however you forgot to account of integer overflow as the sum might be larger than integer so use long long int or long long to store the sums.