[CodeForces] [614A] Link/Cut Tree

Problem Description

Loading...

Problem Analysis

Because pow loses precision,
I used repeated multiplication instead.
For the maximum value,
since res may overflow __int64,
the termination condition only needs to be written before res is multiplied:
res>r/k
which is equivalent to writing at the start of the loop
res>r (because res=res*k has already been executed at that point)

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include<stdio.h>
int main() {

//	freopen("input.txt","r",stdin);
//	freopen("ACoutput.txt","w",stdout);

	__int64 l,r,k;
	while(scanf("%I64d %I64d %I64d",&l,&r,&k)!=EOF) {
		bool flag=false;
		__int64 res=1;
		while(1) {
			if(res>=l&&res<=r) {
				printf("%I64d ",res);
				flag=true;
			}
			if(res>r/k)
				break;
			res*=k;
		}
		if(!flag)
			printf("-1");
		printf("\n");

	}
	return 0;
}

Problem link: 【CodeForces】[614A]Link/Cut Tree

This post is licensed under CC BY-NC-SA 4.0. If it helped, or if you have anything to say, the comment box below is open.
Page views —
Unique visitors —

Loading...