All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Numbers
All odd digit (Posted on 2020-10-05) Difficulty: 2 of 5
Find all positive integers n such that the decimal representation of n2 consists of odd digits only.

No Solution Yet Submitted by Danish Ahmed Khan    
No Rating

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution solution | Comment 3 of 7 |
1^2 = 1
3^2 = 9

are the only two squares with all odd digits.

Further squares all have at least two digits. The even numbers of course end in an even digit, whose square is also even.

Of the odd last digits the following list is all the possible last two digits for squares of odd numbers of two or more digits (the squares mod 100):

 01 09 25 49 81
 21 69 25 89 61
 41 29 25 29 41
 61 89 25 69 21
 81 49 25 09 01
 01 09 25 49 81
 21 69 25 89 61
 41 29 25 29 41
 61 89 25 69 21
 81 49 25 09 01
 
All contain an even digit as the next to last digit.
 
Producing the array was a challenge in the MATLAB language that I am learning, especially the distinction between char format, which is already considered an array of characters, and the string format, which is a single scalar consisting of more than one character, so its length (measured in how many entries in its vector) is only 1:
 
for n=101:2:199
    if mod(n,10)== 1
        i=0;
    end
    nsq=string(n*n);
    l=length(char(nsq));
    dig2=substr(nsq,(l-1):l);
    i=i+1;
    dig2=double(dig2);
    row(i)=dig2;
    if mod(n,10)==9
        fprintf(' %02d %02d %02d %02d %02d\n',row)
    end
end 

where substr() is defined by

function outstr = substr(x,r)
 c=char(x);
 c2=c(r);
 outstr=string(c2);
end

  Posted by Charlie on 2020-10-05 10:49:40
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (0)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2024 by Animus Pactum Consulting. All rights reserved. Privacy Information