info

MAPS OS v1.1.4 © 2025

Glory to the Segtree

Glory to the Algorithm.

String Art OnlineGo home

Login to view input

no submission

Login to submit an answer

Problem Leaderboard

Problem Leaderboard

String Art Online

Dear Solver,

This is your reminder for the new episode airing of String Art Online (SAO), as per your notification settings on MyAlgorithmList (MAL).

In this episode, Kirito is pondering the difference between the real world and the digital. He believes the sole difference to be the amount of data. Therefore, he is examining datastreams. He examines the numbers 1–10000 inclusive, representing the number of players initially trapped in the floating castle of Aincrad.

Since he has mastered the art of dual-wielding, he examines them under two different perspectives, that is, two given numbers.

He is particularly interested in contiguous subsections of this stream that can be read the same, back to front, balanced like the two blades in his hands. He calls such subsections special.

The method of investigation for both is the same. He takes the next number from the sequence 1–10000, modulos it by a given number, and then gets its binary representation. He then appends this to the rest of the data generated so far. He then re-examines the stream so far in its entirety to count the number of unique special subsections in it after appending this new number and adds it to his total. Remember this is the number of unique subsections in this NEW string — you can re-count subsections from the old one, before appending, when calculating for the new one. i.e. if you counted 101 in the previous iteration, you may count it once more.

Complete this challenge to earn the Starburst Stream title on MyAlgorithmList!

Attached at the end are two numbers. Attempt the above process on both numbers respectively and multiply the total sums at the end together.

Since the answer may be very large, mod it by 10^9 + 7.

NOTE: 0 in binary is 0 here, and for other numbers, consider the binary representation from the leftmost 1, ignoring all leading zeroes.
Here is a small example where we limit the range to 1–3 and consider the numbers 2 and 3.

Input Format:

  • The input consists of two integers on one line, the two numbers you should run his process on respectively.

Output:

  • The output is a single integer: (TotalA * TotalB) % (10^9 + 7)

Sample Input:

2
3

Sample Output:

48

Sample Explanation:

TotalA = 0  
TotalB = 0  

1  
1 % 2 = 1 -> 1 (binary) -> 1 (stream so far)  
TotalA += 1 (for the substring '1')  

1 % 3 = 1 -> 1 (binary) -> 1 (stream so far)  
TotalB += 1 (for the substring '1')  

2  
2 % 2 = 0 -> 0 (binary) -> 10 (stream so far)  
TotalA += 2 (for the substring '1', '0')  
TotalA = 3  

2 % 3 = 2 -> 10 (binary) -> 110 (stream so far)  
TotalB += 3 (for the substring '1', '11', '0')  
TotalB = 4  

3  
3 % 2 = 1 -> 1 (binary) -> 101 (stream so far)  
TotalA += 3 (for the substring '1', '0', '101')  
TotalA = 6  

3 % 3 = 2 -> 10 (binary) -> 1100 (stream so far)  
TotalB += 4 (for the substring '1', '11', '0', '00')  
TotalB = 8  

TotalA * TotalB = 48

By the end, Kirito realises what he's been doing by examining a stream of data as strings. It's been string art, online, the entire time.