2022csp-j 复赛第一题,题面:https://noi.yecheng.tv/p/CSPJ2022A

乘方

#include<bits/stdc++.h>  
using namespace std;  
int main()  
{  
	int a,b;  
	cin>>a>>b;  
	if(a==1)  
	{  
		cout<<1;  
		return 0;  
	}  
	else  
	{  
		long long ans=1;  
		for(int i=1;i<=b;i++)  
		{  
			ans*=a;  
			if(ans>1e9)  
			{  
				cout<<-1;  
				return 0;   
			}  
		}  
		cout<<ans;  
	}  
	return 0;  
 }