为什么-1的点总不对
查看原帖
为什么-1的点总不对
1271310
mysb楼主2025/1/20 09:02
为什么-1的点总不对
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=5e7,mod=1e9+7;
int dp[N];
int n,m;
int a[N];
int v[N],w[N],sum,mx,mmx;
int t=1,p,q;
int l,r,ans=1;
signed main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>l>>r>>n;
	if(n==1){
		if(l>=1){
			cout<<1;
			return 0;
		}
		else {
			cout<<-1;
			return 0;
		}
	}
	while(ans<l){
		ans*=n;
	}
	if(!(ans>=l&&ans<=r)){
		cout<<-1;
		return 0;
	}
	bool fg=0;
	while(ans<=r){
		fg=1;
		cout<<ans<<" ";
		ans*=n;
		if(ans<0)return 0;
	}
	if(!fg)cout<<-1;
	return 0;
}
2025/1/20 09:02
加载中...