User Profile

Collapse

Profile Sidebar

Collapse
SlashGeek
SlashGeek
Last Activity: May 6 '12, 03:24 PM
Joined: Dec 7 '11
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • SlashGeek
    replied to Changing complexity from O(n) to O(1)
    in C
    this is my whole code :
    Code:
    #include<stdio.h>
    int main()
    {
       unsigned long int t , n , m , i ;
       unsigned long long int s ,s1 ;
       scanf("%ld",&t);
       while(t--)
       {   s = 0 ;
          scanf("%ld",&n) ;
          scanf("%ld",&m) ; 
          for(i=m ; i<=(2*n-1) ; i+=m)
          {
                if(i<=n+1)
    ...
    See more | Go to post

    Leave a comment:


  • SlashGeek
    started a topic Changing complexity from O(n) to O(1)
    in C

    Changing complexity from O(n) to O(1)

    For the following code :
    Code:
     s = 0 ;
     for(i=m ; i<=(2*n-1) ; i+=m)
          {
                if(i<=n+1)
                { s+=(i-1)/2 ; }
               else
                { s+=(2*n-i+1)/2 ; }  
          }
    I want to change the complexity of the code from O(n)
    to O(1) . So I wanted to eliminate the for loop . But as
    the sum "s" stores values like (i-1)/2 or (2*n-i+1)/2...
    See more | Go to post

  • SlashGeek
    started a topic Stack Overflow
    in C

    Stack Overflow

    I m declaring an array : int a[1000000] in C. The program on
    execution becomes non responsive possibly because of stack overflow as a[100000] is working fine. I don't want to declare my array dynamically as I have to use all length in
    a[1000000] at a tym. Somehow I hv managed to get successful execution on ideone.com but its still not working on my system and I m still getting TLE on an online judge. Plz suggest a faster method (if...
    See more | Go to post

  • SlashGeek
    started a topic Weird Output
    in C

    Weird Output

    For the code given under, I'm getting 4200496 as output.

    #include<stdio. h>
    int main()
    {
    printf("%d",pri ntf);
    return 0;
    }
    Why I'm getting output for this code and what does the value signify???
    I've used DEV C++ IDE.
    See more | Go to post
No activity results to display
Show More
Working...