bool is_sum(int n)
{
    for (int p = 1; p <= n/2; p++)
        if (is_abundant(p) && is_abundant(n-p))
            return true;
    return false;
}
Exemple #2
0
int main(int argc,char* argv[])
{
	clock_t begin, end;
	double time_spent;
	
	begin= clock();
	make_primes(28123);
	int abundants[10000] = {0};
	int* a = abundants-1;
	bool summable[28123]= {false};

	for(int i =0; i < 28123;i++)
		if(is_abundant(i)){*(a++)=i;}
	for(int i = 0; i <= a-abundants;i++)
	{
		for(int j = i; j<= a-abundants;j++)
		{
			if(abundants[i]+abundants[j] > 28123)break;
			summable[abundants[i]+abundants[j]]=true;
		}
	}
	int sum = 0;
	for(int i =0;i < 28123;i++)
		if(!summable[i])
			sum+=i;
	printf("%d\n",sum);
	end = clock();
	time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
	printf("Time Taken: %f\n",time_spent);		
	return 0;
}
Exemple #3
0
int 
main(int argc, char** argv)
{
    int i, j;
    unsigned long long sum;

    for  (i = 1; i <= MAX; i++) {
        abundant[i] = is_abundant(i);
    }

    for (i = 1; i <= MAX; i++) {
        if (!abundant[i]) 
            continue;
        for (j = 1; j <= MAX; j++) {
            if (!abundant[j])
                continue;
            if (i + j <= MAX)
                is_sum_of_abundant[i + j] = 1;
        }
    }

    sum = 0;
    for (i = 1; i <= MAX; i++) {
        if (!is_sum_of_abundant[i]) 
            sum += i;
    }

    printf("%llu\n", sum);

    return 0;
}
Exemple #4
0
std::vector<int> get_abundant_numbers(int max) {
  std::vector<int> ret;
  for (int i = 1; i <= max; ++i) {
    if (is_abundant(i))
      ret.push_back(i);
  }
  return ret;
}
Exemple #5
0
int main()
{
        int abundant_count;
        int *abundant_numbers;
        int numbers[MAX+1] = { 0 };
        int i, c, k, sum;
        int present;

        // count abundant numbers
        abundant_count = 0;
        for (i = 1; i < MAX; i++) {
                if (is_abundant(i))
                        abundant_count++;
        }
        abundant_numbers = malloc(abundant_count * sizeof(int));

        // store abundant numbers
        k = 0;
        for (i = 1; i < MAX; i++) {
                if (is_abundant(i))
                        abundant_numbers[k++] = i;
        }

        // mark integers that CAN be written
        // as the sum of two abundant numbers
        for (i = 0; i < abundant_count; i++) {
                for (k = i; k < abundant_count; k++) {
                        sum = abundant_numbers[i] + abundant_numbers[k];
                        if (sum <= MAX)
				numbers[sum] = 1;	
			else
				break;
                }
        }

        // sum numbers that are not marked in the array
	sum = 0;
	for (i = 1; i <= MAX; i++)
		if (!numbers[i])
			sum += i; 

	printf("%d", sum);
        return 0;
}
Exemple #6
0
int main(void)
{
  
  int i, j, sum, lim = 28124;
  
  int* abundant        = malloc( sizeof(int) * lim );
  int* abundant_notsum = malloc( sizeof(int) * lim ); 
  
  i = 1;
  while(lim-i)
  {
    abundant[i] = is_abundant(i);
    abundant_notsum[i] = 1;
    i++;
  }
  
  i = 1;
  while(lim-i)
  {
    if( abundant[i] ) 
    {    
      j = 1;
      while(lim-j)
      {
        if( abundant[j] && (i+j < lim) )
          abundant_notsum[i+j] = 0;       
        j++;
      }        
    }
    i++;
  }
  
  sum = 0;
  i = 1;
  while(lim-i)
  {
    if ( abundant_notsum[i] )
      sum += i;
    i++;
  }
  
  printf("%i\n", sum);
  
  free(abundant);
  free(abundant_notsum);
    
  exit(0);
}
Exemple #7
0
uint32_t* abundants(uint32_t min, uint32_t max) {
	const size_t BBS = 32;
	size_t bbc = 1;

	uint32_t* abundants = calloc(bbc * BBS, sizeof(uint32_t));

	uint32_t c = 0;
	for (uint32_t i = min; i <= max; i++) {
		if (is_abundant(i)) {
			abundants[c++] = i;

			if (c >= (bbc * BBS) - 1) {
				abundants = realloc(abundants, ++bbc * BBS * sizeof(uint32_t));
			}
		}
	}

	abundants[c] = 0;
	return abundants;
}
Exemple #8
0
int main()
{
    int abundant_numbers[10000] = {0};
    int abundant_count = 0;

    int i = 0;
    for (i = 0; i < MAX; ++i)
    {
        if (is_abundant(i))
        {
            abundant_numbers[abundant_count] = i; 
            ++abundant_count;
        }
    }

    int sum_of_abundants[MAX * 2 + 1] = {0};

    int j = 0;
    for (i = 0; i < abundant_count; ++i)
    {
        for (j = 0; j < abundant_count; ++j)
        {
            sum_of_abundants[abundant_numbers[i] + abundant_numbers[j]] = 1;
        }
    }

    int result_sum = 0;
    for (i = 1; i < MAX; ++i)
    {
        if (!sum_of_abundants[i])
        {
            result_sum += i;
        }
    }

    printf("%d\n", result_sum);
    return 0;
}
Exemple #9
0
int print_properties_num(longnum num)
{
	printf("%llu:\nprime factors: ", num);
	print_prime_factors(num);
	printf("\n");

	if ( is_abundant(num) ) printf(" abundant");
	if ( is_amicable(num) ) printf(" amicable");
	if ( is_apocalyptic_power(num) ) printf(" apocalyptic_power");
	if ( is_aspiring(num) ) printf(" aspiring");
	if ( is_automorphic(num) ) printf(" automorphic");
	if ( is_cake(num) ) printf(" cake");
	if ( is_carmichael(num) ) printf(" carmichael");
	if ( is_catalan(num) ) printf(" catalan");
	if ( is_composite(num) ) printf(" composite");
	if ( is_compositorial(num) ) printf(" compositorial");
	if ( is_cube(num) ) printf(" cube");
	if ( is_deficient(num) ) printf(" deficient");
	if ( is_easy_to_remember(num) ) printf(" easy_to_remember");
	if ( is_ecci1(num) ) printf(" ecci1");
	if ( is_ecci2(num) ) printf(" ecci2");
	if ( is_even(num) ) printf(" even");
	if ( is_evil(num) ) printf(" evil");
	if ( is_factorial(num) ) printf(" factorial");
	if ( is_fermat(num) ) printf(" fermat");
	if ( is_fibonacci(num) ) printf(" fibonacci");
	if ( is_google(num) ) printf(" google");
	if ( is_happy(num) ) printf(" happy");
	if ( is_hungry(num) ) printf(" hungry");
	if ( is_hypotenuse(num) ) printf(" hypotenuse");
	if ( is_lazy_caterer(num) ) printf(" lazy_caterer");
	if ( is_lucky(num) ) printf(" lucky");
	if ( is_mersenne_prime(num) ) printf(" mersenne_prime");
	if ( is_mersenne(num) ) printf(" mersenne");
	if ( is_narcissistic(num) ) printf(" narcissistic");
	if ( is_odd(num) ) printf(" odd");
	if ( is_odious(num) ) printf(" odious");
	if ( is_palindrome(num) ) printf(" palindrome");
	if ( is_palindromic_prime(num) ) printf(" palindromic_prime");
	if ( is_parasite(num) ) printf(" parasite");
	if ( is_pentagonal(num) ) printf(" pentagonal");
	if ( is_perfect(num) ) printf(" perfect");
	if ( is_persistent(num) ) printf(" persistent");
	if ( is_power_of_2(num) ) printf(" power_of_2");
	if ( is_powerful(num) ) printf(" powerful");
	if ( is_practical(num) ) printf(" practical");
	if ( is_prime(num) ) printf(" prime");
	if ( is_primorial(num) ) printf(" primorial");
	if ( is_product_perfect(num) ) printf(" product_perfect");
	if ( is_pronic(num) ) printf(" pronic");
	if ( is_repdigit(num) ) printf(" repdigit");
	if ( is_repunit(num) ) printf(" repunit");
	if ( is_smith(num) ) printf(" smith");
	if ( is_sociable(num) ) printf(" sociable");
	if ( is_square_free(num) ) printf(" square_free");
	if ( is_square(num) ) printf(" square");
	if ( is_tetrahedral(num) ) printf(" tetrahedral");
	if ( is_triangular(num) ) printf(" triangular");
	if ( is_twin(num) ) printf(" twin");
	if ( is_ulam(num) ) printf(" ulam");
	if ( is_undulating(num) ) printf(" undulating");
	if ( is_untouchable(num) ) printf(" untouchable");
	if ( is_vampire(num) ) printf(" vampire");
	if ( is_weird(num) ) printf(" weird");

	printf("\n\n");
	return 0;
}
Exemple #10
0
int main(int argc, char *argv[] )
{
	uint16_t *abundant = NULL ;

	size_t abundant_size = 0 ;

	uint16_t i, j, k ;

	uint16_t found_flag ;

	uint32_t sum_2_abundants ;
	uint32_t sum = 1 ;

	/* sum is initialized to 1 because 1 cannot be expressed as a sum of two 	   abundants.*/
	/* fill the array telling if characters are abundant */

	for( i = 12; i < 29000; ++ i )
	{
		if( is_abundant( i ) )
		{
			++ abundant_size ;

			abundant = realloc( (void *) abundant,
					sizeof(uint16_t) * abundant_size ) ;

			abundant[abundant_size - 1] = i ;

#if extra_printing
			printf("adding abundant number %d\n", i );
#endif
		}

	}

#if extra_printing
	printf("beginning search for sums of abundant numbers\n");
#endif

	/* first loop for finding the numbers that cannot be written as hte sum of two nonabundant numbers */

	for(i = 2; i < 28124 ; ++i )
	{
		found_flag = 0 ;

		/* second loop for finding first  abundant number to make sum */
		/* j starts as 1 because 1 is first abundant number */
		for( j = 0;  abundant[j] < i /*&& j < abundant_size*/ ; ++ j )
		{

			if(found_flag == 1) break ;

			/* third loop for finding second abundant number to */
			/* make sum ( i ) */
			for( k = 0; k < abundant_size /*&& abundant[k] < i*/ ; ++k )
			{
				sum_2_abundants = abundant[k] + abundant[j] ;

				if( sum_2_abundants == i )
				{
#if extra_printing
					printf("%d = %d + %d \n"    ,
							i           ,
							abundant[j] ,
							abundant[k] );
#endif
					found_flag = 1 ;

					/*set found flag to break out*/

				}

				else if( sum_2_abundants > i ) break ;
			}
		}

		/* add i to sum if a sum of 2 abundants is not found */

		if(found_flag == 0 ) sum += i ;
	}

	printf("the sum of all numbers which cannot be expressed as a sum of 2 abundant numbers is %d\n", sum );

	return 0;
}
Exemple #11
0
int main()
{
	linkedlist *abundants = calloc(1,sizeof(linkedlist));
	abundants->next = NULL;
	abundants->data = 0;

	unsigned int i = 1;
	double process = 0;
	unsigned int nbr_of_abundants = 0;

	while(i<MAXVAL)
	{
		if(is_abundant(i))
		{
			add_abundant(abundants,i);
			nbr_of_abundants++;
		}
		process = (double)i/MAXVAL;
		i++;		
	}
	/* Getting rid of the first number in the list wich was 0.. */
	linkedlist * first = abundants->next;

	free(abundants);

	unsigned int * abundantnbrs = calloc(nbr_of_abundants,sizeof(unsigned int));

	i = 0;

	linkedlist *ptr = first;
	while(i<nbr_of_abundants)
	{
		abundantnbrs[i] = ptr->data;
		ptr = ptr->next;
		i++;
	}

	unsigned int u = 28123;
	while(can_be_written_as_sum(abundantnbrs,nbr_of_abundants,u))
	{
		u--;
	}

	int sum = 0;

	i = 0;

	while(i<=u)
	{
		if(!can_be_written_as_sum(abundantnbrs,nbr_of_abundants,i))
		{
			sum += i;
		}
		printf("Process: %i \n",i);
		i++;
	}

	printf("\n\n");
	printf("The answer is: %i\n",sum);

	free_abundants(first);

	
	free(abundantnbrs);

	return 0;
}