6 kyu

Sequence of squared digits

Description:

Introduction

Consider the first 16 terms of the series below:

11,32,53,94,135,176,217,298,379,460,541,622,703,784,865,1026...

which is generated by this sequence:

11,21,21,41,41,41,41,81,81,81,81,81,81,81,81,161....

Each term u of the sequence is obtained by finding the:

(last power of 2) * 10 + 1 if u is not a power of 2.

oru * 10 + 1 if u is a power of 2.

Please note that u starts at 1 and not 0.

Task

Given variable n, calculate the nth term of the series shown above.

Tests

  • 10 fixed tests: First 10 terms
  • 100 random tests: 1e100 < n < 1e101

Notes:

  • Naive solutions won't pass, so don't try to generate the sequence.
  • Aim for a sublinear solution (constant time is possible but not required).
Algorithms
Mathematics
Logic

More By Author:

Check out these other kata created by WestwardLand968

Stats:

CreatedOct 13, 2020
PublishedOct 13, 2020
Warriors Trained608
Total Skips26
Total Code Submissions487
Total Times Completed129
Python Completions129
Total Stars17
% of votes with a positive feedback rating87% of 42
Total "Very Satisfied" Votes35
Total "Somewhat Satisfied" Votes3
Total "Not Satisfied" Votes4
Total Rank Assessments12
Average Assessed Rank
6 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
8 kyu
Ad
Contributors
  • WestwardLand968 Avatar
  • Blind4Basics Avatar
Ad