What is the running time of the following piece of code ?

void function(int n){
     for(int i=1; i<=n; i++)
          for(int j=1; j<=n;j+=i)
               printf("1");
}


Difficulty level
This exercise is mostly suitable for students
O(n*log(n))

Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Target sum in a BST