用计算机编程的方法证明2^67-1不是素数
用计算机编程的方法证明2^67-1不是素数证明2的67次方减1不是素数 这道题昨晚想了一整晚,没想出好的思路。哪位大神点拨下。
#include <stdio.h> // 余数 mydiv( 被除数, 除数, 商 ) unsigned long long mydiv( const unsigned numerator[], unsigned long long denominator, unsigned quotient[] ) { unsigned long long remainder = 0; for( size_t i=0; i!=3; ++i ) { remainder = remainder*1000000000 + numerator[i]; quotient[i] = (unsigned)(remainder/denominator); remainder %= denominator; } return remainder; } int mycompare( const unsigned a[], unsigned long long b ) { unsigned b_[] = { (unsigned)(b/1000000000000000000), (unsigned)(b%1000000000000000000/1000000000), (unsigned)(b%1000000000) }; for( size_t i=0; i!=3; ++i ) { if( a[i] < b_[i] ) return -1; if( a[i] > b_[i] ) return +1; } return 0; } void myprint( const unsigned a[] ) { if( a[0] != 0 ) printf( "%u%09u%09u", a[0], a[1], a[2] ); else if( a[1] != 0 ) printf( "%u%09u", a[1], a[2] ); else printf( "%u", a[2] ); } int main( void ) { const unsigned n[] = { 147, 573952589, 676412927 }; // 2^67-1 for( unsigned long long denom=3; ; denom+=2 ) { unsigned quotient[3]; unsigned long long remainder = mydiv( n, denom, quotient ); if( remainder == 0 ) { printf( "%llu * ", denom ); myprint( quotient ); putchar( '\n' ); break; } if( mycompare(quotient,denom) < 0 ) { puts( "it is a prime number." ); break; } } }