**Limited-time discount**for early adopters: Pro Membership is only

**/month**when paid yearly.% OFF

**Want a free month?**Refer a friend.

Active In

International Olympiad in Informatics

Indian Computing Olympiad (ICO)

Competitive Programming

Artificial Intelligence

USA Computing Olympiad

Game Development

Learn from Home

International Mathematics Olympiad

Featured Contributions

comment in this discussion

This is for Pro Members

We like how far you've come. Upgrade today and get access to all of CommonLounge.

Already a member? Sign in.

Read more… (2 words)

comment in this discussion

comment in this discussion

I tried it too. I am not sure why that happens but it's likely due to dynamic memory allocation and all the overheads from function calls, error checking etc. When I wrote my own priority queue, it worked quite well. Here's the code if you are interested.

Read more… (47 words)

comment in this discussion

I got the correct answer for all test cases except for 7th. Anyone facing the same issue?

Read more… (17 words)

comment in this discussion

The swap function that you wrote doesn't work. You need to swap pointers.

Read more… (13 words)

comment in this discussion

comment in this discussion

comment in this discussion

Ok (Spoiler alert). For example, say to need to find the answer when N = 12.

If a divides b, it is written as a|b. Let c keep the string count.

Since 1|12, we add 2^1 = 2 periodic strings. c = 2.

Since 2|12, we add 2^2 = 4 periodic strings. However, we are couting strings of length 1 twice. So we subtract them. So instead we add 2^2 - 2 = 2. c = 4.

Since 3|12, we add 2^3. Again we are overcounting strings of length 1 twice so we add 2^3 - 2 = 6. c = 10.

Since 4|12, we add 2^4. However, now we are overcounting strings of length 1 and 2 twice. So we add 2^4 - 2 - 2 = 12. c = 22.

6|12 so we add 2^6. But we are overcounting strings of length 1, 2 and 3. So add 2^6 - 2 - 2 - 6 = 54. c = 76.

Read more… (162 words)