Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8726699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:18:07+00:00 2026-06-13T08:18:07+00:00

for(i = 1; i < n*n; i++){ for(j = 1; j < i*i; j++){

  • 0
for(i = 1; i < n*n; i++){
    for(j = 1; j < i*i; j++){
        if(j % i == 0){
            for(k=0; k < j; k++){
                count++;
            }
        }
    }
}

My attempt at a solution:

j iterates up to i*i = n^4. For the ‘k’ loop, we have the sum of k from 1 to n^4 which is n^4(n^4-1)/2. So the runtime is O(n^8). This strikes me as too high, but I don’t see an error.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T08:18:08+00:00Added an answer on June 13, 2026 at 8:18 am

    The outer loop executes n2 times. The next loop executes a total of ∑i=1n2 i2, which is O(n6).

    The innermost loop only runs when j is a multiple of i, which happens i times for each value of i. The innermost loop executes j times for each such value of j: i, 2i, 3i, and so forth until i*i. Thus, the innermost loop executes ∑j=1i ij times, which is O(i3), for each i.

    Therefore, the total running time is ∑i=1n2 O(i3) + O(n6), which is O(n8) since ∑i=1n2 O(i3) = O(n8).

    (Note that I’m assuming the second loop increments j++, not i++. The answer is rather different if it’s i++).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I actually have this working, but its very ugly, and its keeping me awake
I have a little Problem but don't know the Solution! I have wrote a
This is possibly a problem with possibly no optimal solution. Suppose I have a
Alright, Im going about this, with what is probably a really complicated solution, but
Does COUNT(*) have any significant impact for MySQL performance if query already has GROUP
TOPIC_COUNT_SQL = SELECT COUNT(*) FROM topics_topic WHERE topics_topic.object_id = maps_map.id AND topics_topic.content_type_id = %s
SELECT COUNT(`t`.id) FROM `product` `t` INNER JOIN `category` `c1` ON ( `c1`.id ='15' )
recently I became interested in the subset-sum problem which is finding a zero-sum subset
This task has already been asked/answered, but I recently had a job interview that
I'm new at programming, new on this site too, so hello... I'm attempting to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.