54pts求助
查看原帖
54pts求助
1075962
Mcfire05楼主2024/8/6 11:32
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;
ull qpow(ull a,ull b){
	ull ans=1,base=a;
	while(b > 0){
		if(b & 1){
			ans *= base;
    	}
        base *= base;
		b >>= 1;
	}
	return ans;
}
int main(){
	ull qwq,awa,w,tmp=0,cnt;
	cin>>qwq>>awa>>w;
	if(w==1 and qwq==1){
		cout<<1;
		return 0;
	}
	for(ull i=0;;i++){
		if(i==0){
			if(qpow(w,i)<=awa and qpow(w,i)>=qwq){
				cout<<qpow(w,i)<<" ";
				tmp++;
			}else{
				break;
			}
		}else{
			if(qpow(w,i)<=awa and qpow(w,i)>=qwq and qpow(w,i)>=w){
				cout<<qpow(w,i)<<" ";
				tmp++;
			}else{
				break;
			}
		}
	}
	if(tmp==0){
		cout<<-1;
	}
}
2024/8/6 11:32
加载中...