The validation function primenot only returns false; even if it functions properly, your main loop is not looking for input coefficients at all, but rather just the largest prime, less than or equal to it. In pseudo code, your code is equivalent:
foo(n):
x := 0 ;
foreach d from 1 to n step 1:
if is_prime(d):
x := d
return x
is_prime(d):
not( d % 1 == 0 )
. , :
factors(n):
fs := []
d := 2
while ( d <= n/d ):
if ( n % d == 0 ): { n := n/d ; fs := append(fs,d) }
else: { d := d+1 }
if ( n > 1 ): { fs := append(fs, n) }
return fs
. , , , . , , , 1473 .
( ). , 1. , , . , , , , .
, : append
append(fs,d):
return d
1, d , , d, , , .. d , .