Thread: Mod question...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    101

    Mod question...

    How can I calculate it in C?

    20X(77^2) mod 119

    It's too big... even can't use pow/%/mod.....

    thx!!

  2. #2
    Registered User biosx's Avatar
    Join Date
    Aug 2001
    Posts
    230
    How is that too big? A modulus can't get that big. Here is the code I used to check it:

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    
    int main()
    {
       long int number;
    
       number = (20 * pow(77, 2));
       number = number % 119; 
          
       printf("Answer: %d\n", number);
    
       system("PAUSE");
       return 0;
    }
    I think your problem was the face that you didn't use a long int.

    Good luck

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    197
    Hi!
    Did you know that you can even declare a long long int in C?
    It works, but I have never used it.

    klausi
    When I close my eyes nobody can see me...

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    101
    Originally posted by klausi
    Hi!
    Did you know that you can even declare a long long int in C?
    It works, but I have never used it.

    klausi
    However... it doesn't work on me with long long int......
    anyway... thx!!

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Accurate arithmetic on truly large numbers requires the support of a library.

    Here's one example
    http://swox.com/gmp/

  6. #6
    Registered User
    Join Date
    Oct 2001
    Posts
    101
    Originally posted by biosx
    How is that too big? A modulus can't get that big. Here is the code I used to check it:

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    
    int main()
    {
       long int number;
    
       number = (20 * pow(77, 2));
       number = number % 119; 
          
       printf("Answer: %d\n", number);
    
       system("PAUSE");
       return 0;
    }
    I think your problem was the face that you didn't use a long int.

    Good luck

    I mean 20^77....

    It shouldn't be number = (pow(20,77));??

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Python mod sched question
    By Overworked_PhD in forum Tech Board
    Replies: 2
    Last Post: 04-26-2009, 03:16 PM
  2. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  3. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 09:22 PM
  4. MOD Question from a newbie
    By BOOGIEMAN in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 12-18-2001, 09:02 AM