Đăng nhập để hỏi chi tiết


Hãy luôn nhớ cảm ơn và vote 5*
nếu câu trả lời hữu ích nhé!
Bài 1:
def p(n):
if n < 2: return 0
for i in range(2, int(n**0.5)+1):
if n % i == 0: return 0
return 1
with open('timso.inp') as f:
s = f.readline().strip()
m = -1
for x in '0123456789':
t = s.replace('X', x, 1)
if t[0] == '0': continue
a = sum(int(c) for c in t)
if p(a): m = max(m, int(t))
with open('timso.out', 'w') as f:
f.write(str(m))
Bài 2:
from collections import Counter as C
with open('denmau.inp') as f:
a = f.readline().strip()
q = int(f.readline())
l = [f.readline().strip() for _ in range(q)]
def c(s):
d = C(s)
return [d['D'], d['V'], d['X']]
b = c(a)
r = 0
for x in l:
y = c(x)
z = [b[i] + y[i] for i in range(3)]
if z[0] == z[1] == z[2]: r += 1
with open('denmau.out', 'w') as f:
f.write(str(r))
Hãy giúp mọi người biết câu trả lời này thế nào?
\begin{array}{c} \color{#F5FAFF}{F} \color{#9EC1E9}{u} \color{#7DA6D9}{r} \color{#5C8BCD}{i} \color{#7A9CCF}{n} \color{#8BB0D9}{a} \color{#8BB0D9}{F} \color{#7A9CCF}{o} \color{#5C8BCD}{r} \color{#7DA6D9}{c} \color{#9EC1E9}{a} \color{#F5FAFF}{l} \color{#9EC1E9}{o} \color{#FFFFFF}{s} \end{array}
/**
* author: furina focalors
* from : A3K59 DHV
* created: 20.08.2025
**/
#include<bits/stdc++.h>
#define hutao long long
using namespace std;
hutao CTLL(char c)
{
return c - '0';
}
bool snt(hutao n)
{
if(n<=1) return false;
if(n<=3) return true;
if(n%2==0 || n%3==0) return false;
for(hutao i=5;i*i<=n;i+=6)
if(n%i==0 || n%(i+2)==0)
return false;
return true;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
string s;
cin>>s;
hutao tong=0;
hutao t=0;
for(hutao i=0;i<(hutao)s.length();i++)
{
if(s[i]>='0' && s[i]<='9') {
tong+=CTLL(s[i]);
} else
{
t=i;
}
}
string ans="";
for(hutao d=9;d>=0;d--)
{
hutao sum=tong+d;
if(snt(sum))
{
string tam=s;
tam[t]=char('0'+d);
if(ans=="")
{
ans=tam;
}
else
{
ans=max(ans,tam);
}
}
}
cout<<ans;
}
Hãy giúp mọi người biết câu trả lời này thế nào?
Bảng tin