Solve g(sod(p)) = p where:
p is a prime number.
g(x) = Ax^2 + Bx + C
A, B, and C are single digit positive integers.
sod() is the sum of digits function
and, the combined digits of A, B, C, p and sod(p) include each of the digits 1 through 9 exactly once.
Find A, B, C, p and sod(p)
clc, clearvars
for pNo=1:9592
p=nthprime(pNo);
s=0;
pdgts=num2str(p) ;
if isequal(unique(pdgts),sort(pdgts)) && ~contains(pdgts,'0')
l=length(pdgts) ;
for i=1:l
s=s+str2double(pdgts(i));
end
digused=[pdgts num2str(s)];
if isequal(unique(digused),sort(digused))
if length(digused)==6
if ~contains(digused,'0')
abc=setdiff('123456789',digused);
abcs=perms(abc);
for i=1:length(abcs)
abc=abcs(i,:);
a=str2double(abc(1));
b=str2double(abc(2));
c=str2double(abc(3));
g=a*s^2+b*s+c;
if g==p
disp([a b c p s])
end
end
end
end
end
end
sd=s;
end
finds
9 8 5 2437 16
as A B C p sod(p)
as 9*16^2 + 8*16 + 5 = 2437
|
Posted by Charlie
on 2021-12-31 10:29:10 |