Skip to content

Instantly share code, notes, and snippets.

@Jack-Saleem
Last active July 17, 2016 14:08
Show Gist options
  • Save Jack-Saleem/935b7e55cda48fec7e7c808b95a19443 to your computer and use it in GitHub Desktop.
Save Jack-Saleem/935b7e55cda48fec7e7c808b95a19443 to your computer and use it in GitHub Desktop.
codeforces 614A LinkOrCutTree program in java
import java.math.BigInteger;
import java.util.Scanner;
public class LinkOrCutTree
{
public static void main(String[] args)
{
Scanner z=new Scanner(System.in);
BigInteger bl=new BigInteger(z.next());
BigInteger br=new BigInteger(z.next());
BigInteger bk=new BigInteger(z.next());
int i=0;
BigInteger ba;
String x="";
while(true)
{
ba=bk.pow(i);
if(ba.compareTo(br)==1)
break;
if((ba.compareTo(bl)==0 || ba.compareTo(bl)==1) && (ba.compareTo(br)==0 || ba.compareTo(br)==-1))
x+=ba+" ";
i++;
}
if(x.length()/2==0)
System.out.println("-1");
else
System.out.println(x.trim());
z.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment