Problem:


Score : 200 points

Problem Statement

You are given a positive integer X.
Find the largest perfect power that is at most X.
Here, a perfect power is an integer that can be represented as b^p, where b is an integer not less than 1 and p is an integer not less than 2.

Constraints

1 ≤ X ≤ 1000

X is an integer.

Input

Input is given from Standard Input in the following format:

X

Output

Print the largest perfect power that is at most X.

Sample Input 1

10

Sample Output 1

9

There are four perfect powers that are at most 10: 1, 4, 8 and 9.
We should print the largest among them, 9.

Sample Input 2

1

Sample Output 2

1

Sample Input 3

999

Sample Output 3

961



Sample input:
10


Sample output:
9

Submission status: Time Limit Exceeded

Solution code:
import math


X = int(input())

p = 1
q = 1
tmp = 1

while p < math.sqrt(X):
    q = 1
    while 1:
        if p ** q > X:
            break
        else:
            if tmp < p ** q:
                tmp = p ** q
            q += 1
    p += 1

print(tmp)

Submission status: Time Limit Exceeded

Solution code:
X = int(input())
ans = 1
for b in range(1, X-1):
    for p in range(2, X-1):
        if b**p <= X:
            ans = max(ans, b**p)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
X = int(input())
ans = 1
for b in range(1, X-1):
    for p in range(2, X-1):
        if ans < b**p <= X:
            ans = b**p

print(ans)

Submission status: Time Limit Exceeded

Solution code:
X = int(input())
ans = 1
for b in range(1, X):
    for p in range(2, X):
        if ans < b**p <= X:
            ans = b**p

print(ans)

Submission status: Time Limit Exceeded

Solution code:
x=int(input())
mx=1
for i in range(2,32):
  p=2
  while i**p<=x:
    if i**p > mx:
      mx = i**p
      p+=1
print(mx)

Submission status: Time Limit Exceeded

Solution code:
A=input()
a=int(A)
n2=1
for i in range(a):
    for x in range(a):
        if n2 <= a:
            n1=(i+2)**(x+2)
            if n2 <= n1 and n1 <= a:
                n2 = n1
                #print(n2)
                n1
print(n2)

Submission status: Time Limit Exceeded

Solution code:
A=input()
a=int(A)
n1=0
n2=1
for i in range(a):
    for x in range(a):
        if n2 <= a:
            n1=(i+2)**(x+2)
            if n2 <= n1 and n1 <= a:
                n2 = n1
                #print(n2)
                n1
print(n2)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# from numpy import array, sum

MAX_DIVIDER = 32 # 32 ** 2 = 1024 > 1000

X =int(input())

li = set()

b = 1
while b < MAX_DIVIDER:
	c = b * b
	while c < 1000:
		li.add(c)
		c *= b
	b += 1

while X > 0:
	if X in li:
		print(X)
		break
	else:
		X -= 1

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# from numpy import array, sum

MAX_DIVIDER = 32 # 32 ** 2 = 1024 > 1000

X =int(input())

li = set()

b = 1
while b < MAX_DIVIDER:
	c = b * b
	while c < 1000:
		li.add(c)
		c *= b

while X > 0:
	if X in li:
		print(X)
		break
	else:
		X -= 1

Submission status: Time Limit Exceeded

Solution code:
# -*- coding:utf-8 -*-
if __name__ == "__main__":
    x = int(input())
    ans = float('-inf')
    for p in range(1,x+1):
        for b in range(2, x+2):
            if p**b <= x:
                ans = max(ans, p**b)
    else:
        print(ans)

Submission status: Time Limit Exceeded

Solution code:
x = int(input())
a = int(x**(1/2))
max_ = 1
    
while a >= 1:
    i = 2
    while a**i < x:
        if max_ <= a**i:
            max_ = a**i
        i += 1
    a -=1
print(max_)

Submission status: Time Limit Exceeded

Solution code:
x = int(input())
ans = 1
for i in range(2, 1000):
    j = 2
    while i**j <= x:
        ans = max(ans, i**j)
    j += 1
    if i > x:
        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#! /usr/bin/env python3

N = int(input())
ans = 0
for b in range(1, 999):
    for p in range(2, 999):
        if b ** p <= N : ans = max(ans, b ** p)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
n=int(input())
l=math.log(n,2)
while(0==0):
  b=0
  if n==1000:
    print(n)
    break
  for j in range (2,int(l)+1):
    if n**(1/j)==int(n**(1/j)):
      print (n)
      b=1

  n=n-1
  if b==1:
    break

Submission status: Time Limit Exceeded

Solution code:
from math import sqrt

x = int(input())
sqrt_x = int(x)

ans = 1
for b in range(sqrt_x):
    for p in range(sqrt_x-1):
  
        exp = (b+1)**(p+2)

        if exp<=x and ans<=exp:
            ans = exp

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from math import sqrt

x = int(input())
sqrt_x = int(x)

ans = 1

for b in range(sqrt_x):
  
  for p in range(sqrt_x-1):
  
    exp = (b+1)**(p+2)

    if exp<=x and ans<=exp:
      ans = exp

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from math import sqrt

x = int(input())
sqrt_x = int(x)

ans = 1

for b in range(1, sqrt_x):
  
  for p in range(2, sqrt_x+1):
  
    exp = (b)**(p)

    if exp<=x and ans<=exp:
      ans = exp

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
x = int(input())

maxs = []
for i in range(x):
    max = 0
    for j in range(x):
        if (i+1) ** (j+2) <= x:
            max = (i+1) ** (j+2)
            maxs.append(max)
        else:
            if j == 0:
                max = (i+1) ** (j+2)
                # maxs.append(max)
    # else:
    #     maxs.append(max)


maxs.sort()
# print(maxs)
print(maxs[-1])

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!

INPUT=int(input())
b=1
p=2
END=0
while True:
    while True:
        now_num = b**p
        if b == 1:
            end_num=now_num
            break
        elif p==2 and INPUT<now_num:
            END = 1
            break
        elif INPUT < now_num:
            end_num = b**(p-1)
            break
        else:
            p+=1
        
    if END == 1:
        ans=end_num
        break
    b+=1
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
X = int(input())

p = 2
while p > 1:
    a = 1**2
    if a > X:
        p = 0
        a = a-1
        print(a)
    else:
        a += 1

Submission status: Time Limit Exceeded

Solution code:
X=int(input())
max=1
for j in range(2,X):
    for i in range(1,X):
        if i**j<=X and i**j>max:
            max=i**j
print(max)

Submission status: Time Limit Exceeded

Solution code:
X = int(input())

for i in range(X, 0, -1):
    tmp = i
    if X % tmp:
        continue
    while tmp <= X:
        tmp *= tmp
    if tmp == X:
        print(i)

Submission status: Time Limit Exceeded

Solution code:
X = int(input())

for i in range(X, 0, -1):
    tmp = i
    while tmp <= X:
        tmp *= tmp
    if tmp == X:
        print(i)

Submission status: Accepted

Solution code:
x=int(input())
res=0
for b in range(x+1):
    for p in range(2,x+2):
        if res<(b**p)<=x:
            res=b**p
        elif b**p>x:
            break
print(res)

Submission status: Accepted

Solution code:
x = int(input())
ans = 0
for i in range(x+1):
    for j in range(2,10):
        if i**j <=x:
            ans = max(ans,i**j)
print(ans)

Submission status: Accepted

Solution code:
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 6)
mod = 10**9+7
cnt = 0
ans = 0
num = []
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
AL = al.upper()

N = k()
if N == 1:
    print(1)
    sys.exit()
 
for i in range(N,-1,-1):
    for j in range(1,int(N**0.5)+1):
        for k in range(2,11):
            if j**k == i:
                print(i)
                sys.exit()

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.buffer.readline
in_n = lambda: int(input())
in_nn = lambda: map(int, input().split())
in_s = lambda: input().rstrip().decode('utf-8')
in_map = lambda: [s == ord('.') for s in input() if s != ord('\n')]

MOD = 10**9 + 7
INF = 8 * 10**18


def main():

    x = in_n()

    dp = [False] * 1100
    dp[1] = True

    for i in range(2, 110):
        for j in range(2, 20):
            now = i**j
            if now <= 1000:
                dp[now] = True
            else:
                break

    for i in range(x, 0, -1):
        if dp[i]:
            print(i)
            break


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

def main():
    x = int(input())
    ans = 0
    for b in range(1, 1000):
        for p in range(2, 10):
            if x >= b ** p:
                ans = max(ans, b ** p)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from math import *

x = int(input())

lst1 = list(range(2, int(sqrt(1000)) + 1))
lst2 = [1, 1000]

for n in lst1:
   i = 2
   while n ** i < 1000:
      lst2.append(n ** i)
      i += 1

lst2 = list(set(lst2))
lst2.sort()

for i in range(len(lst2)):
   if x < lst2[i]:
      print(lst2[i - 1])
      exit()

print(lst2[-1])

Submission status: Accepted

Solution code:
import math
x = int(input())

res = 1
for b in range(2, math.ceil(math.sqrt(x))):
    p = 2
    while b**(p+1) <= x:
        p += 1
    res = max(res, b ** p)
print(res)

Submission status: Accepted

Solution code:
def answer(x: int) -> int:
    if x < 4 :
        return 1

    result = 1
    for b in range(2, x + 1):
        for p in range(2, x + 1):
            exp = pow(b, p)
            if exp <= x:
                result = max(result, exp)
            else:
                break

    return result


def main():
    x = int(input())
    print(answer(x))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
ans = 0
for i in range(1, N + 1):
    for j in range(2, 20):
        if i ** j > N:
            continue
        ans = max(i ** j, ans)
print(ans)

Submission status: Accepted

Solution code:
x = int(input())
ans = 1
for i in range(1,x+1):
  for j in range(2,11):
    if i**j <= x:
      ans = max(ans,i**j)
    else:
      break
print(ans)

Submission status: Accepted

Solution code:
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def main():
    n = int(input())
    answers=[]

    if n<=3:
        print(n)
        exit()

    for b in range(2,n):
        #b**2からb**10まで調べる
        for p in range(2,11):
            if b**p > n:
                break
            elif b**p <=n:
                answers.append(b**p)
            else:
                continue
    print(max(answers))
                

if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
import math

X = int(input())

ans = 1
for b in range(int(math.sqrt(X)) + 1):
    for p in range(10):
        if b ** p <= X:
            ans = max(ans, b ** p)
        else:
            break

print(ans)

Submission status: Accepted

Solution code:
x = int(input())
ans = 1000000
for b in range(1,32):
    for p in range(2,10):
        if x-b**p < 0:
            continue
        ans = min(ans,abs(x-(b**p)))
print(x-ans)

Submission status: Accepted

Solution code:
x = int(input())
ans = 1
cnt = 1
for i in range(1,x):
    cnt = i
    for j in range(9):
        cnt *= i
        if cnt > x:
            break
        if cnt > ans:
            ans = cnt
print(ans)

Submission status: Accepted

Solution code:
X = int(input())
ans = 1
for i in range(2, X + 1):
    for j in range(2, X + 1):
        a = i ** j
        if a > X:
            break
        elif a > ans:
            ans = a
print(ans)

Submission status: Accepted

Solution code:
x = int(input())
ans = 0
for i in range(1,32):
    for j in range(2,10):
        if i**j <= x:
            ans = max(ans,i**j)
print(ans)

Submission status: Accepted

Solution code:
a=int(input())
d=0
e=0
for i in range(40):
  b=i+2
  while b<=a:
    b=b*(i+2)
    e=e+1
  c=b/(i+2)
  if e>1:
    if d<=c:
      d=c
      e=0
  else:
    e=0
if d==0:
  print(1)
else:
  print(int(d))

Submission status: Accepted

Solution code:
x = int(input())
ans = 1
for i in range(2,int(x ** 0.5) + 1):
    k = 1
    temp = 1
    while temp<=x:
        ans = max(ans,temp)
        temp = i ** k
        k += 1
print(ans)

Submission status: Accepted

Solution code:
x = int(input())
ans = 1
for i in range(1,x):
    for j in range(2,50):
        if i**j<=x:
            ans = max(ans,i**j)
        else:
            break
    if i**2>x:
        break
print(ans)

Submission status: Accepted

Solution code:
x = int(input())
# p >= 2, b >= 1
if x == 1:
    ans = 1
else:
    ans = 0
    for i in range(1, x+1):
        for j in range(2, x+1):
            e = i**j
            if e <= x:
                ans = max(ans, e)
            else:
                break
print(ans)

Submission status: Accepted

Solution code:
X = int(input())

ans = 0
for i in range(1, int(X**0.5)+1):
    for j in range(2, 1000):
        tmp = pow(i, j)
        if tmp > X:
            break
        ans = max(ans, tmp)

print(ans)

Submission status: Accepted

Solution code:
x = int(input())
tmp = 1
for b in range(1, x):
    for p in range(2,x):
        if b**p <= x:
            tmp = max(tmp, b**p)
        else:
            break
print(tmp)

Submission status: Accepted

Solution code:
N = int(input())

ans = 1
for i in range(2,N+1):
    tmp = 2
    while i**tmp<=N:
        ans = max(ans,i**tmp)
        tmp += 1
print(ans)

Submission status: Accepted

Solution code:
import sys
 
X = int(sys.stdin.readline())
ans = 0
for i in range(X+1):
    for j in range(2, 11):
        tmp = pow(i, j)
        if tmp <= X:
            ans = max(ans, tmp)
print(ans)

Submission status: Accepted

Solution code:
x = int(input())

ans = 1
for i in range(2, int(x**(1/2)//1+1)):
    v = 1
    while v*i <= x:
        v *= i
    ans = max(ans, v)
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
ans=1
for b in range(2,100):
    tmp=b
    for p in range(2,10):
        tmp*=b
        if tmp<=n :
            ans=max(ans,tmp)
print(ans)

Submission status: Accepted

Solution code:
X = int(input())
ans = []
ans.append(1)
for i in range(2, X):
    a = i*i
    while a <= X:
        ans.append(a)
        a *= i
print(max(ans))

Submission status: Accepted

Solution code:
x = int(input())

ans = 0
if x <=2:
    ans = x
else:
    for i in range(1, x+1):
        for j in range(2, x+1):
            if i**j <= x:
                ans = max(ans, i**j)
            elif i**j > x:
                break

print(ans)

Submission status: Accepted

Solution code:
X = int(input())
n = 1
if X<=3:
    print(1)
elif X==4:
    print(4)
else:
    n = 4
    for i in range(2,int(X**0.5)+1):
        b = i
        k = 1
        while b**k<=X:
            k += 1
        k -= 1
        if k>=2:
            n = max(n,b**k)
    print(n)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

X = int(input())

s = set([1])
for i in range(min(2, X), X):
    cnt = 2
    while i**cnt<=X:
        s.add(i**cnt)
        cnt += 1

print(max(s))

Submission status: Accepted

Solution code:
x=int(input())
ans=1
for a in range(2,1000):
    p=2
    while a**p<=x:
        ans=max(ans,a**p)
        p+=1
print(ans)

Submission status: Accepted

Solution code:
MAX = 35
N = int(input())
ans = 1
for i in range(2,MAX+1):
  t = i*i
  while t <= N:
    ans = max(ans,t)
    t *= i
print(ans)

Submission status: Accepted

Solution code:
x = int(input())
bekis = [1]
for i in range(2,35):
    for j in range(2,15):
        v = i**j
        if v > x: break
        bekis.append(v)

bekis.sort()
print(bekis[-1])

Submission status: Accepted

Solution code:
def main():
    X = int(input())
    ans = 1
    for i in range(2, X+1):
        for j in range(2, 11):
            if i**j > X:
                break
            else:
                ans = max(ans, i**j)
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys, math
lines = [s.rstrip("\n") for s in sys.stdin.readlines()]
x, = [int(num) for num in lines.pop(0).split(" ")]
max_base = int(math.sqrt(x))
max = 1
for base in range(2, max_base + 1):
    i = 2
    while True:
        tmp_max = base ** i
        if tmp_max <= x:
            if tmp_max > max:
                max = tmp_max
            i += 1
        else:
            break
print(max)

Submission status: Accepted

Solution code:
import sys
n=int(input())

ans=[]

if n==1:
    print('1')
    sys.exit()

for i in range(n//2):
    for j in range(n//2):
        if i**j<=n:
            ans.append(i**j)

print(max(ans))

Submission status: Accepted

Solution code:
x = int(input())
expotential = [0] * (x + 1)
expotential[1] = 1
for b in range(2, x+1):
	t = b * b
	while(t <= x):
		expotential[t] = 1
		t *= b
for i in range(x, 0, -1):
	if expotential[i]:
		print(i)
		break

Submission status: Accepted

Solution code:
x=int(input())
ans = 0
for i in range(1,32):
  for j in range(2,11):
    if i**j <= x:
      ans = max(ans,i**j)
print(ans)

Submission status: Accepted

Solution code:
X = int(input())
lst = [1]
for i in range(2, 32):
    for j in range(2, 10):
        x = i ** j
        if x <= 1000:
            lst.append(x)
if X in lst:
    print(X)
else:
    lst.append(X)
    lst2 = sorted(lst)
    n = lst2.index(X)
    print(lst2[n-1])

Submission status: Accepted

Solution code:
X = int(input())

ans = 1
for i in range(2, X+1):
  t = i*i
  while t <= X:
    ans = max(ans, t)
    t *= i

print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

x = int(input())

def prime_factorize(n):
    prime_factors = {}
    i = 2
    while i ** 2 <= n:
        exp = 0
        while n % i == 0:
            exp += 1
            n //= i
        if exp:
            prime_factors[i] = exp
        i += 1

    if n != 1:
        prime_factors[n] = 1
    return prime_factors

ans = 1
for i in range(2, x + 1):
    prime_factors = prime_factorize(i)
    exps = set(prime_factors.values())
    if len(exps) == 1 and exps != {1}:
        ans = i
print(ans)

Submission status: Accepted

Solution code:
X=int(input())
ans=1
for i in range(2,int(X**0.5)+1):
    x=i
    while x<=X:
        ans=max(ans,x)
        x*=i
print(ans)

Submission status: Accepted

Solution code:
x = int(input())
max_val = 1
for i in range(1, x):
    for j in range(2, x):   
        val = i ** j
        if val > x:
            break
        elif val > max_val:
            max_val = val
print(max_val)

Submission status: Accepted

Solution code:
x = int(input())
ans = 1
for i in range(x):
    for j in range(2,10): 
        if i**j <= x:
            ans = max(ans,i**j)
            #print(ans,i,j)
        else:
            break

print(ans)

Submission status: Accepted

Solution code:
x = int(input())
ans = 0
for i in range(x):
    for j in range(2,10): 
        if i**j <= x:
            ans = max(ans,i**j)
            #print(ans,i,j)
        else:
            break

if ans == 0:
    ans = 1

print(ans)

Submission status: Accepted

Solution code:
X = int(input())
ans = 1
i = 2
while i * i <= X:
  a = i
  while a * i <= X:
    a *= i
  ans = max(ans, a)
  i += 1
print(ans)

Submission status: Accepted

Solution code:
X = int(input())

maxi = 0

if X < 4:
    print(1)
    exit()

for i in range(1, X+1):
    for j in range(2, X+1):
        if i**j <= X and i**j >= maxi:
            maxi = i**j
        if i**j > X:
            break

print(maxi)

Submission status: Accepted

Solution code:
X = int(input())
cnt = 1
for b in range(1,X):
    for p in range(2,X):
        if b**p <= X:
          cnt = max(cnt, b**p)
        else: break
print(cnt)

Submission status: Accepted

Solution code:
X = int(input())
nums = set()
nums.add(1)
for b in range(2, 40):
    p = 2
    while True:
        if b**p <= 1000:
            nums.add(b**p)
            p += 1
        else:
            break
ans = -1
for num in nums:
    if num <= X:
        ans = max(ans, num)
print(ans)

Submission status: Accepted

Solution code:
import math
X = int(input())

ls = []
for i in range(2,math.floor(math.sqrt(X))+1):
  for j in range(2,10):
    if i ** j <= X:
      ls.append(i ** j)
      
print(max(ls) if ls else 1)

Submission status: Accepted

Solution code:
def main():
    x = int(input())
    expo_list = []

    for i in range(1, 1000):
        for j in range(2, 10):
            expo_list.append(i ** j)

    expo_list.sort(reverse=True)

    for expo in expo_list:
        if expo <= x:
            print(expo)
            break


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n ** 0.5 // 1 )) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append((i, cnt))
    if temp != 1:
        arr.append((temp, 1))
    if arr == []:
        arr.append((n, 1))
    return arr

def solve():
    X = int(input())
    for i in range(X, 0, -1):
        F = factorization(i)
        mi = min(f[1] for f in F)
        if mi > 1 and all([f[1] % mi == 0 for f in F]):
            print(i)
            exit()
    print(1)

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
# row = [int(x) for x in input().rstrip().split(" ")]
# n = int(input().rstrip())
# s = input().rstrip()

def resolve():
    import sys
    input = sys.stdin.readline

    x = int(input().rstrip())

    num_set = set()
    for i in range(1, x+1):
        num = i * i
        while num <= x and i not in num_set:
            num_set.add(num)
            num = num * i

    print(max(num_set))

if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
x = int(input())

ans = 1
for i in range(2, x):
    if i * i > x:
        break

    now = i
    while now * i <= x:
        now *= i
    if now > ans:
        ans = now

print(ans)

Submission status: Accepted

Solution code:
            
X=int(input())

if X==1:
    print(1)
    exit()

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

while True:
    a=prime_factorize(X)
    temp=[]
    c=1
    sw=True
    if len(a)==1:
        sw=False
    for i in range(len(a)-1):
        if a[i]!=a[i+1]:
            temp.append(c)
            c=0
        c+=1
    temp.append(c)

    for j in range(len(temp)-1):
        if temp[j]!=temp[j+1] or temp[j]==1:
            sw=False
    if sw==True:    
        print(X)
        exit()
    X-=1

Submission status: Accepted

Solution code:
n = int(input())
t = [1, 4, 8, 9, 16, 25, 27, 32, 36, 49, 64, 81, 100,
     125, 121, 128, 144, 169, 196, 216, 225, 243, 256,
     289, 324, 343, 361, 400, 441, 484, 512, 529, 576,
     625, 676, 729, 784, 841, 900, 961, 1000, 1024, 1296]

res = 0
for tt in t:
    res = tt if tt <= n else res
print(res)

Submission status: Accepted

Solution code:
n = int(input())
s = set()
for i in range(1, 32):
    s.add(i ** 2)

for i in range(1, 11):
    s.add(i ** 3)

for i in range(1, 7):
    s.add(i ** 4)

for i in range(1, 5):
    s.add(i ** 5)
    s.add(i ** 6)
    s.add(i ** 7)
    s.add(i ** 8)
    s.add(i ** 9)
    s.add(i ** 10)

t = list(s)
t.sort()
t = [x for x in t if x <= 1000]

res = 0
for tt in t:
    res = tt if tt <= n else res
print(res)

Submission status: Accepted

Solution code:
x = int(input())
ans = 0
for i in range(1, 100):
    for j in range(2, 10):
        a = i**j
        if a <= x and x-a <= x-ans:
            ans = a
print(ans)

Submission status: Accepted

Solution code:
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

x = ri()
max_ = 0
for i in range(int(x**0.5), 0, -1):
    for j in range(1, 10):
        if i**j <= x:
            max_ = max(i**j, max_)
        else:
            break
print(max_)

Submission status: Accepted

Solution code:
X = int(input())
exps = []
for b in range(1,34):
  for p in range(2,11):
    x = b**p
    if x < 1001:
      exps.append(x)
exps = list(set(exps))
exps.sort()
for a in exps[::-1]:
  if X >= a:
    print(a)
    break

Submission status: Accepted

Solution code:
x = int(input())

table = [False] * -~x
table[1] = True
for i in range(2, 32):
    j = i * i
    while j <= x:
        table[j] = True
        j *= i

print(max(i for i in range(x + 1) if table[i]))

Submission status: Accepted

Solution code:
X = int(input())
ans = 1
for i in range(2, 32):
    for j in range(2, 10):
        if i ** j > X:
            continue
        ans = max(ans, i ** j)
print(ans)

Submission status: Accepted

Solution code:
X = int(input())
b = 2
p = 2
ans = 1
for b in range(1, X+1):
    for p in range(2, X+1):
        beki = b ** p
        if beki <= X:
            ans = max(ans, beki)
        else:
            break
print(ans)

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
  return int(readline())
x = I()
ans = 1
for b in range(2,1001):
    for p in range(2,24):
        if b**p <= x:
            ans = max(ans,b**p)
        else:
            break
print(ans)

Submission status: Accepted

Solution code:
ans = []
X = int(input())
for i in range(1,50):
  for j in range(2,20):
    if (i ** j)<= X:
      ans.append(i**j)
print(max(ans))

Submission status: Accepted

Solution code:
x = int(input())
print(max([pow(i, j) for i in range(1, 32)
           for j in range(2, 10) if pow(i, j) <= x]))

Submission status: Accepted

Solution code:
X=int(input())
ans=0
for i in range(X+1):
    if i*i<=X:
        sum=i*i
        for j in range(X):
            if i**j>X:
                break
            sum=max(sum,i**j)
    else:
        break
    ans=max(ans,sum)

print(ans)

Submission status: Accepted

Solution code:
import math
X = int(input())
ans = 1
Y = math.floor(math.sqrt(X))
for i in range(2, Y+1):
    for j in range(2, 10):
        a = i**j
        if a <= X:
            ans = max(ans, a)
print(ans)

Submission status: Accepted

Solution code:
import collections
X = int(input())
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

for i in range(X):
  J = X - i
  d = collections.Counter(prime_factorize(J))
  dv = list(d.values())
  if len(set(dv)) == 1 and dv[0] >= 2:
    print(J)
    break
  if dv == []:
    print(1)
    break

Submission status: Accepted

Solution code:
def m_pow(x, n) -> int:
    """
    O(log n)
    """
    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2

    return (K * x)


ans = 1
x = int(input())
for i in range(2, 1001):
    for j in range(2, 1001):
        n = m_pow(i, j)
        if n <= x:
            ans = max(n, ans)
        else:
            break

print(ans)

Submission status: Accepted

Solution code:
X = int(input())
s = [0] * (X + 1)
for i in range(1, 1001):
    for j in range(2, 1001):
        n = i**j
        if n > X: break
        s[n] += 1
for i in range(X, 0, -1):
    if s[i]:
        print(i)
        exit()

Submission status: Accepted

Solution code:
X = int(input())
if X==1:
    print(1)
else:
    cmax = 1
    for i in range(2,int(X**0.5)+1):
        k = 2
        while i**k<=X:
            cmax = max(cmax,i**k)
            k += 1
    print(cmax)

Submission status: Accepted

Solution code:
x = int(input())

ans = [1]
for i in range(2, 1001):
  p = 2
  while i**p <= 1000:
    ans.append(i**p)
    p += 1
while not x in ans:
  x -= 1
print(x)

Submission status: Accepted

Solution code:
import math
def resolve():
    x = int(input())
    sqrt_x = int(math.sqrt(x))
    al = list()
    for i in range(2, 10):
        for j in range(sqrt_x, 0, -1):
            if j**i <= x:
                al.append(j**i)
                break
    al = sorted(al)
    print(al[-1])
resolve()

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    x = int(readline())
    s = set()

    for i in range(1, 1001):
        for j in range(2, 16):
            if i ** j <= x:
                s.add(i ** j)
            else:
                break

    l = list(s)
    l.sort(reverse=True)

    print(l[0])


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
import math as m
if n < 4:
  print(1)
  exit(0)
  
perfect = 1
for b in range(2,int(n**0.5)+1):
  p = int(m.log(n,b))
  x = b**(p+1)
  if x > n:
    x = b**p
  perfect = max(perfect,x)
  #print(b,x)
  if perfect == n:
    break

print(perfect)

Submission status: Accepted

Solution code:
n = int(input())
a = {1}
for b in range(2,n):
  p = 2
  x = b**p
  while x <= n:
    a.add(x)
    x = b**p
    p += 1

print(max(a))

Submission status: Accepted

Solution code:
x=int(input())
ans=0
if x==1:
  print(1)
  exit()
for i in range(1,x):
  for j in range(2,10):
    if i**j<=x:
      ans=max(ans,i**j)
    else:
      break
print(ans)

Submission status: Accepted

Solution code:
X = int(input())
S = set([1])
for i in range(2,X):
  b = 2
  while(i**b<=X):
    S.add(i**b)
    b += 1

ans = max(S)
print(ans)

Submission status: Accepted

Solution code:
x=int(input())
c=1
for b in range(1,x):
    for p in range(2,x):
        if b**p<=x:
            c=max(c,b**p)
        else:
            break
print(c)

Submission status: Accepted

Solution code:
x = int(input())
pr = [1]
for i in range(2,32):
    for j in range(2,10):
        if (i**j <= 1000)&(i**j not in pr):
            pr.append(i**j)
print(max([k for k in pr if k <= x]))

Submission status: Accepted

Solution code:
x=int(input())
m=-1000
if 1<=x<=3:
  print(1)
  exit()
else:
  for b in range(2,x+1):
   for p in range(2,11):
    if x>=b**p:
      m=max(m,b**p)
   

print(m)