In Hackerland every character has a weight. The weight of an English uppercase alphabet A-Z is given below :
A = 1
B = 2*A + A
C = 3*B + B
D = 4*C + C
….
Z = 26*Y + Y
The weight made up of these characters is the summation of weights of each character. Given a total string weight, determine shortest string of given weight. If there is more than one solution, return the lexicographically smallest of them. For example, given weight = 25, and the weights of the first few characters of the alphabets are A=1, B=3, C=12, D=60 it is certain that no letter larger than C is required. Some of the strings with a total weight equal to the target are ABBBBC, ACC, AAAAAAABBBBBB. The shortest of these is ACC. While any permutation of these characters will have same weight, this is the lexicographically smallest of them.
Example
Input
20
Output
AABBC
is this correct?
d={“A”:1}
for i in range(2,27):
val=64+i
t=chr(val)
t1=i*d[chr(val-1)]+d[chr(val-1)]
d[t]=t1
s=int(input())
i=”A”
while i in d and d[i]0 and i>=”A”:
if d[i]<=s:
s=s-d[i]
l.append(i)
else:
i=chr(ord(i)-1)
print(*l[::-1],sep="")
n = int(input())
di = {}
li = [1,3]
for i in range(4,29):
li.append(i*li[-1])
li = li[:27]
x = 0
for i in range(65,91):
if li[x] not in di:
di[li[x]] = chr(i)
x += 1
s = ”
for i in range(26,-1,-1):
# print(n//li[i])
if n//li[i] > 0:
s += di[li[i]]*(n//li[i])
n = n%li[i]
print(”.join(sorted(s)))
Data,ans,sume={“A”:1},[],0
for i in range(2,27):
Data[chr(64+i)]=i*Data[chr(63+i)]+Data[chr(63+i)]
key=list(reversed([i for i in Data.keys()]))
nu=int(input())
#Lowest
for i,x in enumerate(key):
if nu>=Data[x]:
idx=i
break
while sume<=nu:
if (Data[key[idx]]+sume)<=nu:
ans.append(key[idx])
sume+=Data[key[idx]]
#print(sume)
elif idx==25:
break
else:
idx+=1
print(*ans[::-1],sep="")
l = [1]
res = []
s = “”
for i in range(1,26):
l.append((i+1)*l[i-1]+l[i-1])
n = int(input())
for i in range(len(l)):
if(n == l[i]):
print(chr(i+97))
elif(n = 0):
n-=res[-1]
s += chr((len(res)-1)+97)
else:
res.pop()
print(s[::-1])
n=int(input())
s=’ABCDEFGHIJKLMNOPQRSTUVWXZ’
c=4;res=”
d={}
d[‘A’]=1
d[‘B’]=3
for i in range(2,len(s)):
d[s[i]]=d[s[i-1]]*c
if d[s[i]]>n:
del d[s[i]]
break
c+=1
l=list(d.keys())
print(l)
for i in range(len(l)-1,-1,-1):
r=n//d[l[i]]
res+=l[i]*r
n=n%d[l[i]]
if n==0:
break
print(res[::-1])
dict={‘A’:1}
for i in range(2,27):
a=i+64
dict[chr(a)]=i*dict[chr(a-1)]+dict[chr(a-1)]
w=int(input())
str=””
for i in range(26,0,-1):
if(dict[chr(i+64)]>w):
continue
else:
n=w//dict[chr(i+64)]
str=n*chr(i+64)+str
w-=n*dict[chr(i+64)]
print(str)
def WeightedStrings(n):
c=’A’
key=1
mf=3
d={1:’A’}
for i in range(66,91):
key*=mf
d[key]=chr(i)
mf+=1
keys=list(d.keys())
res=””
while n!=0:
i=0
while i<26:
if n==keys[i]:
res+=d[n]
n=0
break;
elif n<keys[i]:
res+=d[keys[i-1]]
n-=keys[i-1]
break;
i+=1
return res[::-1]
print(WeightedStrings(int(input())))
import java.util.*;
public class WeightedStrings{
static int values[]=new int[26];
static void insertValues(){
values[0]=1;
int prev=1;
for(int i=1;i<26;i++){
values[i]=(i+1)*prev+prev;
prev=values[i];
}
}
static StringBuffer formedString(StringBuffer sb,int k){
int low=0;
int high=25;
while(k!=0){
int ind=findfloor(k,low,high);
sb.insert(0,(char)(ind+'A'));
k=k-values[ind];
}
return sb;
}
static int findfloor(int k,int low,int high){
int ans=-1;
while(low<=high){
int mid=(low+high)/2;
if(values[mid]<=k){
ans=mid;
low=mid+1;
}
else
high=mid-1;
}
return ans;
}
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
insertValues();
int k=sc.nextInt();
StringBuffer sb=new StringBuffer();
StringBuffer res=formedString(sb,k);
System.out.println(res);
}
}
n=int(input())
dict={‘A’:1,’B’:3,’C’:12,’D’:60,’E’:360,’F’:2520,’G’:20160,’H’:181440}
s=0
l=[]
for x,y in sorted(dict.items(),key=lambda x:x[1]):
s=s+y
if s<=n:
l.append([x,y])
l.sort(key=lambda x:x[1],reverse=True)
print(l)
s=""
for i in range(len(l)):
t=n//l[i][1]
n=n-(t*l[i][1])
s=s+t*l[i][0]
l2=list(s)
l2.reverse()
print("".join(l2))
d={“A”:1}
for i in range(2,27):
key=chr(i+64)
d[key]=i*d[chr(i+63)]+d[chr(i+63)]
def find_series(n):
d1={}
l=[]
string=”ABCDEFGHIJKLMNOPQRSTUVWXYZ”
for i in d:
if d[i]=l[i]:
a= n//l[i]
n-=(l[i]*a)
l1.append(string[len(l)-i-1]*a)
if n==0:
break
string2=”.join(sorted(l1))
return string2
n=int(input())
print(find_series(n))
a=[‘A’,’B’,’C’,’D’,’E’,’F’,’G’,’H’,’I’,’J’,’K’,’L’,’M’,’N’,’O’,’P’,’Q’,’R’,’S’,’T’,’U’,’V’,’W’,’X’,’Y’,’Z’]
v=[0,1,3]
for i in range(3,27):
v.append(v[i-1]*(i+1))
# print(v)
d=dict()
for i in range(len(a)):
d[a[i]]=v[i+1]
# print(d)
num=int(input())
str=””
max=””
while(num!=0):
for i in a:
if(d[i]>num):
break
max=i
q=num//d[max]
num=num%d[max]
str=q*max+str
print(str)
#include
#include
int main(){
long long int arr[26];
char a[26];
char o[26];
int n;
int j=0,len;
arr[0]=1;
scanf(“%d/n”,&n);
for(int i=1;i<26;i++){
arr[i]=(i+1)*arr[i-1]+arr[i-1];
}
for(int i=0;i0){
for(int i=0;i<26;i++){
if(n=0;i–){
printf(“%c”,o[i]);
}
}