Thread: timeout compilation error... please help me how to get rid of this error

  1. #1
    Registered User
    Join Date
    Feb 2013
    Posts
    8

    timeout compilation error... please help me how to get rid of this error

    Code:
    //to find the largest prime factor of the number i = 600851475143
    
    
    
    
    #include<stdio.h>
    
    
    unsigned long long prime(unsigned long long j);
    unsigned long long max=1;
    
    
    int main()
    {
     unsigned long long i= 600851475143 ,j ;
     for(j = 2;j<i/2 ; j++)
     {
        if(i%j==0)
    	max= prime(j);
    		  }
      printf("%llu",max);
      
      return 0;
    }
    
    
      unsigned long long prime(unsigned long long j)
      {unsigned long long a;
    	for(a=2;a<j/2;a++)
    	{
    	 if(j%a==0)
    	 return max;
    	 }
    	 return j;
    	 }

  2. #2
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    This
    Code:
    unsigned long long i= 600851475143
    gets this warning
    Code:
    main.c:10: warning: integer constant is too large for "long" type
    If you are dealing with primes, I suggest you take a look at the Eratosthene's sieve.
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Run this program, and see if your unsigned long long int system maximum, is large enough to handle the value of i in your program.
    Code:
    #include <stdio.h>
    #include <limits.h>
    
    int main(void) {
       printf("%llu\n",ULLONG_MAX);
       return 0;
    }
    Your code will run very slowly, but that can be fixed later. First things first.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compilation Error (?)
    By anpaolo in forum C Programming
    Replies: 5
    Last Post: 11-01-2012, 05:35 AM
  2. Replies: 6
    Last Post: 01-10-2012, 01:30 PM
  3. Compilation Error
    By samuraiexx in forum C Programming
    Replies: 4
    Last Post: 09-21-2011, 12:19 AM
  4. error: was not declared in this scope compilation error
    By i_r_tomash in forum C Programming
    Replies: 2
    Last Post: 05-27-2010, 07:44 AM
  5. compilation error
    By blue_gene in forum C++ Programming
    Replies: 3
    Last Post: 03-30-2004, 10:48 AM