【Codeforces Round 339 (Div 2)A】【水题 暴力】 LinkCut Tree 输出[l,r]范围内所有的k的幂数

Link/Cut Tree
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, which is based on Splay trees. Specifically, he is now studying the expose procedure.

Unfortunately, Rostislav is unable to understand the definition of this procedure, so he decided to ask programmer Serezha to help him. Serezha agreed to help if Rostislav solves a simple task (and if he doesn't, then why would he need Splay trees anyway?)

Given integers lr and k, you need to print all powers of number k within range from l to r inclusive. However, Rostislav doesn't want to spent time doing this, as he got interested in playing a network game called Agar with Gleb. Help him!

Input

The first line of the input contains three space-separated integers lr and k (1 ≤ l ≤ r ≤ 10182 ≤ k ≤ 109).

Output

Print all powers of number k, that lie within range from l to r in the increasing order. If there are no such numbers, print "-1" (without the quotes).

Examples
input
1 10 2
output
1 2 4 8 
input
2 4 5
output
-1
Note

Note to the first sample: numbers 20 = 121 = 222 = 423 = 8 lie within the specified range. The number 24 = 16 is greater then 10, thus it shouldn't be printed.


#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<ctype.h>
#include<math.h>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<bitset>
#include<algorithm>
#include<time.h>
using namespace std;
void fre() { freopen("c://test//input.in", "r", stdin); freopen("c://test//output.out", "w", stdout); }
#define MS(x,y) memset(x,y,sizeof(x))
#define MC(x,y) memcpy(x,y,sizeof(x))
#define MP(x,y) make_pair(x,y)
#define ls o<<1
#define rs o<<1|1
typedef long long LL;
typedef unsigned long long UL;
typedef unsigned int UI;
template <class T1, class T2>inline void gmax(T1 &a, T2 b) { if (b>a)a = b; }
template <class T1, class T2>inline void gmin(T1 &a, T2 b) { if (b<a)a = b; }
const int N = 0, M = 0, Z = 1e9 + 7, ms63 = 0x3f3f3f3f;
LL l, r, k;
int main()
{
	while (~scanf("%lld%lld%lld", &l,&r,&k))
	{
		bool flag = 0;
		LL x = 1;
		while (1)
		{
			if (x >= l&&x <= r)
			{
				flag = 1;
				printf("%lld ", x);
			}
			double p = (double)x*k;
			if (p > 2e18)break;
			x = x*k;
		}
		if (!flag)printf("-1");
		puts("");
	}
	return 0;
}
/*
【trick&&吐槽】
小心爆int

【题意】
输出[l,r]范围内所有的k的幂数

【类型】
水题 暴力

*/


### Codeforces Round 1028 (Div. 2) 目概述 Codeforces Round 1028 (Div. 2) 是一场包含多个算法问的比赛,涵盖了从简单到复杂的不同难度级别。以下是该比赛的部分目内容及简要说明: #### A. Gellyfish and Flower 在本中,有两个角色:Gellyfish 和 Flower。每个角色有两滴血量,分别用 \(a\) 和 \(c\) 表示 Gellyfish 的血量,用 \(b\) 和 \(d\) 表示 Flower 的血量[^3]。 获胜条件是攻击对方的最低血量,并比较双方的最低血量值。如果 Gellyfish 的最低血量小于 Flower 的最低血量,则 Gellyfish 获胜;否则,Flower 获胜。 #### B. Problem - B - Codeforces B 的具体内容未完全提供,但通常涉及组、字符串或其他据结构的操作。可以参考比赛页面获取完整描述。 #### C. Rectangles C 要求处理矩形的相关问。具体来说,给定一些矩形的边长信息,需要判断某些条件是否满足。时间限制为每组测试用例 2 秒,内存限制为 256 MB[^2]。输入和输出均为标准格式,详细规则可参考比赛页面。 ### 示例代码(A ) 以下是一个实现 A 逻辑的 C++ 程序: ```cpp #include <iostream> #include <algorithm> using namespace std; int main() { int t; cin >> t; while (t--) { int a, b, c, d; cin >> a >> b >> c >> d; int mina = min(a, c); int minb = min(b, d); if (mina < minb) cout << "Flower" << endl; else cout << "Gellyfish" << endl; } } ``` 此代码通过多次循环读取输入并计算两个角色的最低血量,最终输出获胜者名称。 ### 注意事项 - 比赛中的所有目均可以通过官方链接访问,例如 [Codeforces Round 1028 (Div. 2)](http://codeforces.com/contest/1028)[^2]。 - 每道目的详细规则和样例输入输出可在对应页面找到。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值