0% found this document useful (0 votes)
3 views6 pages

With Open

The document contains a series of Python scripts that read input from various files, perform computations, and write the results to output files. Each script handles different tasks such as counting prime numbers, sorting lists, finding maximum and minimum values, and checking conditions on sequences. The scripts demonstrate a variety of programming techniques and algorithms applied to solve specific problems.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views6 pages

With Open

The document contains a series of Python scripts that read input from various files, perform computations, and write the results to output files. Each script handles different tasks such as counting prime numbers, sorting lists, finding maximum and minimum values, and checking conditions on sequences. The scripts demonstrate a variety of programming techniques and algorithms applied to solve specific problems.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

with open("024HH.

INP","r") as klinh:
data=klinh.readlines()
d=int(data[0])
def pfn(d):
summ=0
for a in range(1,d//2+1):
if d%a==0:
summ+=a
return summ
rs=0
for a in range(1,d+1):
if a==pfn(a):
rs+=1
with open("024HH.OUT","w") as klinh:
klinh.writelines(str(rs))

with open("CAU6.INP", "r") as x:


data=x.readlines()
songuyenduongkhanhlinh=list(map(int,data[1].split()))
sapxeptangdankhanhlinh=sorted(songuyenduongkhanhlinh)
ketquakhanhlinh=""
for z in sapxeptangdankhanhlinh:
ketquakhanhlinh+=str(z)+" "
with open("CAU6.OUT", "w") as x:
x.writelines(ketquakhanhlinh)

with open("CAU7.INP","r") as yay:


data=yay.readlines()
hehe=list(map(int,data[0].split()))
hehe.sort()
hehe.reverse()
meomeo=[]
for kiki in range (len(hehe)):
meomeo.append(str(hehe[kiki]))
with open("CAU7.OUT","w") as yip:
yip.writelines(" ".join(meomeo))

with open("CAU20.inp","r")as fin:


data=fin.readlines()
khanhlinh=int(data[0])
haha=list(map(int,data[1].split()))
hihi=sorted(haha)
hehe=sorted(haha,reverse=True)
if haha==hihi or haha==hehe:
hoho="TRUE"
else:
hoho="FALSE"
with open("CAU20.out","w")as fout:
fout.writelines(str(hoho))

with open ("CAU15.INP","r") as f:


data=f.readlines()
N=list(map(int,data[1].split()))
dem=0
for i in range(len(N)):
if i%2==0 and N[i]%2==1:
dem+=1

with open("CAU15.OUT", "w") as f:


f.writelines(str(dem))

with open("CAU14.INP", "r") as fin:


data=fin.readlines()
y=list(map(int,data[1].split()))
y.sort()
linhlonhat=y[-1]
linhlonnhi=y[-2]
ans=str(linhlonhat)+"\n"+str(linhlonnhi)
with open("CAU14.OUT", "w") as fout:
fout.writelines(ans)

with open("CAU10.INP","r")as fin:


data=fin.readlines()
Hello=int(data[0])
Kitty=list(map(int,data[1].split()))
def soZ(alpha):
for k in range(2,int(alpha**(0.5))+1):
if alpha%k==0:
return False
return True
ketquacuoi=0
for k in Kitty:
if soZ(k):
ketquacuoi+=k
final=str(ketquacuoi)
with open("CAU10.OUT","w")as fout:
fout.writelines(final)

def klinh(q):
T=0
for i in range(1,int(q**0.5)+1):
if q%i==0:
T+=i+q//i
if T==2*q:
return True
with open("CAU11.INP","r")as hii:
data=hii.readlines()
he= list(map(int,data[1].split()))
t=0
for e in he:
if klinh(e):
t+=e
with open("CAU11.OUT","w")as hii:
hii.writelines(str(t))

with open("CAU19.INP", "r") as f:


data=f.readlines()
n=int(data[0])
N=list(map(int,data[1].split()))

kq=""
for i in range (n-1,-1,-1):
kq+=str(N[i]) + " "

with open("CAU19.OUT", "w") as f:


f.writelines(kq)

with open("CAU2.INP", "r") as f:


n = int(f.readline().strip())
a = list(map(int, f.readline().strip().split()))
max_value = max(a)
first_max_index = a.index(max_value)
with open("CAU2.OUT", "w") as f:
f.write(f"{max_value}\n")
f.write(f"{first_max_index + 1}\n")

with open("CAU22.INP","r") as f:
data=f.readlines()
N=list(map(int,data[0].split()))
a2=0
a1=0
dem=0
for i in N:
if i==0:
break
dem+=1
if i%3==0:
a2+=1
if i%2==0 and i<0:
a1+=1
with open("CAU22.OUT","w") as f:
f.writelines((str(dem)+"\n"+str(a2)+"\n"+str(a1)))

with open("CAU17.INP", "r") as f:


data=f.readlines()
a=list(map(int,data[0].split()))
b=list(map(int,data[1].split()))
c=a+b
a1=list(sorted(a))
a2=' '.join(str(x) for x in a1)
b1=list(sorted(b))
b2=' '.join(str(y) for y in b1)
c1=list(sorted(c))
c2=' '.join(str(z) for z in c1)
S=a2+"\n"+b2+"\n"+c2
with open("CAU17.OUT", "w") as f:
f.writelines(str(S))

with open("B12.INP", "r") as f:


data=f.readlines()
nx=int(data[0])
mx=list(map(int,data[1].split()))
sx=0
px=0
for i in range(1,len(mx),2):
if mx[i]%2==1:
sx+=mx[i]
px+=1
if px==0:
ketq="Khong ton tai"
else:
ketq=format(sx/px,".2f")
with open("B12.OUT", "w") as f:
f.writelines(str(ketq))

with open("CAU3.INP", "r") as fin:


data = fin.readlines()
klinhh = list(map(int, data[0].split()))
gtln = max(klinhh)
chiso = [hello + 1 for hello, num in enumerate(klinhh) if num == gtln]
with open("CAU3.OUT", "w") as fout:
fout.write(str(gtln) + "\n")
fout.write(" ".join(map(str, chiso)))

with open("017MM.INP", "r") as f:


data = f.readlines()
klinh = list(map(int, data[0].split()))
min_value = min(klinh)
max_value = max(klinh)
min_index = klinh.index(min_value) + 1
max_index = klinh.index(max_value) + 1
with open("017MM.OUT", "w") as f:
f.write(str(max_index) + " " + str(min_index))

with open("019SX.inp","r") as linhh :


data = linhh.readlines()
da = list(map(int,data[1].split()))
jii = ""
yay = ""

da.sort()
for i in da :
jii+=str(i)+" "
da.reverse()
for y in da :
yay+=str(y)+" "
with open("019SX.out","w") as lia :
lia.writelines(jii+"\n"+yay)

with open("CAU12.inp","r") as fin:


data=fin.readlines()
l=int(data[0])
s=list(map(int,data[1].split()))
d=s[2]-s[1]
for i in range(1,l-1):
if s[i+1]-s[i]!=d:
result="FALSE"
else:
result="TRUE"
with open("CAU12.out","w") as fout:
fout.writelines(result)

with open("CAU4.INP","r") as fin:


data = fin.readlines()
hello = int(data[0])
kitty = list(map(int, data[1].split()))
for oi in range(len(kitty)):
if kitty[oi] == min(kitty):
break
with open("CAU4.OUT","w") as fout:
fout.writelines(str(min(kitty)))
fout.writelines("\n")
fout.writelines(str(oi + 1))

with open("007DNT.INP","r") as linh:


data=linh.readlines()
z=int(data[0])
c=0
for a in range(2,z+1):
p=0
for k in range(2,int(a**(0.5)+1)):
if a%k==0:
p=1
break
else:
c+=1
with open("007DNT.OUT","w") as linh:
linh.writelines(str(c))

with open("DEMSO.INP", "r") as f:


data = f.readlines()
hello = int(data[0])
kitty = list(map(int, data[1].split()))
so_am = sum(1 for num in kitty if num < 0)
so_duong = sum(1 for num in kitty if num > 0)
with open("DEMSO.OUT", "w") as f:
f.write(str(so_am) + " " + str(so_duong))

with open("016MM.INP", "r") as f:


data=f.readlines()
n=list(map(int,data[0].split()))
sln=max(n)
snn=min(n)
with open("016MM.OUT", "w") as f:
f.writelines(str(sln)+" "+str(snn))

with open("CAU9.INP", "r") as q:


data=q.readlines()
n=int(data[0])
A=list(map(int, data[1].split()))
def cp(A):
c=0
for k in A:
if k==(round(k**(1/2)))**2:
c+=1
return c
with open("CAU9.OUT", "w") as q:
q.writelines(str(cp(A)))

with open("CAU13.INP", "r") as f:


data=f.readlines()
a=list(map(int,data[0].split()))

x=max(a)
fn=0
fn1=1
B=[0,1]
for i in range (2,x+1):
fi=B[i-1]+B[i-2]
B.append(fi)

kq=""
for k in a:
kq+=str(B[k]) + " "

with open("CAU13.OUT","w") as f:
f.writelines(kq)
with open ("025HN.INP", "r") as f:
data=f.readlines()
A=int(data[0])
for r in range (1,A+1):
kq=0
for l in range (2,r):
if r%l==0:
kq=kq+1
sohuunghi=0
for x in range(1,kq+1):
if x==l:
sohuunghi=sohuunghi+1
with open ("025HN.OUT", "w") as f:
f.writelines(str(sohuunghi))

with open("08TM.INP","r")as fin:


data=fin.readlines()
oi=int(data[0])
oioi=list(map(int,data[1].split()))
giatrilonnhat=max(oioi)
dem=0
for oioioi in oioi:
if oioioi==giatrilonnhat:
dem+=1
kq=str(giatrilonnhat)+" "+str(dem)
with open("08TM.OUT","w")as fout:
fout.writelines(kq)

with open("CAU23.INP", "r") as hh:


data=hh.readlines()
n=list(map(int,data[0].split()))
nhohon=0
chiahet=0
soluong=0
for i in range(1,len(n)):
if n[i]==0:
break
else:
soluong+=1
if n[i]%n[0]==0:
chiahet+=n[i]
if n[i]<n[0]:
nhohon+=1
with open("CAU23.OUT", "w") as kk:
kk.writelines(str(soluong)+"\n"+str(nhohon)+"\n"+str(chiahet))

with open("CAU5.INP", "r") as fin:


data = fin.readlines()
haha = list(map(int, data[0].split()))
gtnn = min(haha)
ketqua = [hehe + 1 for hehe, so in enumerate(haha) if so == gtnn]
with open("CAU5.OUT", "w") as fout:
fout.write(str(gtnn) + "\n")
fout.write(" ".join(map(str, ketqua)))

with open("CAU16.INP", "r") as f:


data=f.readlines()
N=int(data[0])
A=list(map(int,data[1].split()))
B=list(map(int,data[2].split()))
C=str(A[0])+" "+str(B[0])
for i in range (1,N):
C+=" "+str(A[i])+" "+str(B[i])
with open("CAU16.OUT", "w") as f:
f.writelines(str(C))

with open("CAU25.INP", "r") as ddd:


data=ddd.readlines()
L=int(data[0])
s=list(map(int, data[1].split()))
result=0
for z in range(len(s)):
if s[z]==0:
fn=z
break
for z in range(len(s)):
if s[z]==0:
ln=z
for z in range(fn,ln):
result+=s[z]
with open("CAU25.OUT", "w") as nnn:
nnn.writelines(str(result))

with open("CAU21.INP","r")as fin:


data=fin.readlines()
l=int(data[0])
p=list(map(int,data[1].split()))
for e in range(1,l-2):
if p[e]>=p[e+1] and p[e+2]>=p[e+1] or p[e]<=p[e+1] and p[e+2]<=p[e+1]:
rs="TRUE"
else:
rs="FALSE"
with open("CAU21.OUT","w")as fout:
fout.writelines(str(rs))

with open("THUNHI.INP", "r") as f:


data = f.readlines()
a=int(data[0])
b=list(map(int, data[1].split()))
n1=max(b)
b.remove(n1)
n2=max(b)
kq=str(n2)
with open("THUNHI.OUT","w")as fout:
fout.writelines(kq)

with open("09TH.INP","r")as hi:


data=hi.readlines()
n=int(data[0])
N=list(map(int,data[1].split()))
max=max(N)
min=min(N)
ans1=""
ans2=""
N.sort()
for a in N:
ans1+=str(a)+" "
N.reverse()
for b in N:
ans2+=str(b)+" "
with open("09TH.OUT","w")as hu:
hu.writelines(str("min = "+str(min))+"\n"+str("max = "+str(max))+"\n"+str(ans1)+"\n"+str(ans2))

with open("CAU40.INP","r" ) as f:
data=f.readlines()
N1=str(data[1])
N2=str(data[2])
dts='FALSE'
if N2 in N1:
dts='TRUE'
with open("CAU40.OUT","w") as f:
f.writelines(dts)

You might also like