Submission

Status:
[PPPPPPPPPPPPPPPPPPPP]

Score: 100

User: monpluk

Problemset: ยกกำลัง

Language: cpp

Time: 0.015 second

Submitted On: 2025-04-13 17:32:07

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    int t;
    cin >> t;
    vector<long long> ansarr;
    long long mod = 1e9 + 7;
    for(int i=0;i<t;i++){
        long long n,m,ans;
        cin >> n >> m;
        ans = n;
        vector<bool> check;
        while(m!=1){
            if(m%2 == 0){
                check.push_back(true);
                m/=2;
            }else{
                check.push_back(false);
                m--;
            }
        }
        reverse(check.begin(),check.end());
        for(bool valid : check){
            if(valid){
                ans = (ans*ans)%mod;
            }else{
                ans = (ans*n)%mod;
            }
        }
        ansarr.push_back(ans);
    }
    for(long long ans : ansarr){
        cout << ans << "\n";
    }
}