void mod_integer(integer left, integer right, integer result) { integer mod_two_power = create_integer(right.num_components + 1); int i, bit; set_zero_integer(result); set_zero_integer(mod_two_power); mod_two_power.c[0] = 1; for(i=0; i<left.num_components; i++) { for(bit=0; bit<COMPONENT_BITS; bit++) { if ((left.c[i] & (1 << bit)) != 0) { add_integer(result, mod_two_power, result); if (compare_integers(result, right) >= 0) { subtract_integer(result, right, result); } } shift_left_one_integer(mod_two_power); if (compare_integers(mod_two_power, right) >= 0) { subtract_integer(mod_two_power, right, mod_two_power); } } } free_integer(mod_two_power); }
int problem263() { integer testnum = string_to_integer("5"); integer testnum_helper = string_to_integer("5"); integer two = string_to_integer("2"); integer total_src = string_to_integer("0"); integer total_tar = string_to_integer("0"); integer target_dif = string_to_integer("6"); integer dif = string_to_integer("0"); int found = 0; integer lastprime = string_to_integer("5"); //int sexy_count = 0; printf("text here\n"); while (found < 4) { //printf("gets 1\n"); if (miller_rabin(testnum) == PRIME) { subtract_integer(testnum, lastprime, dif); if (compare_integers(dif, target_dif) == 0) { printf("difference between %s and %s is six\n", integer_to_string(testnum), integer_to_string(lastprime)); found++; }else { found = 1; } copy_integer(testnum, lastprime); add_integer(total_src, testnum, total_tar); copy_integer(total_tar, total_src); printf("Total is %s\n", integer_to_string(total_tar)); } add_integer(testnum_helper, two, testnum); copy_integer(testnum, testnum_helper); printf("Tested %s\n", integer_to_string(testnum)); } return 0; }