http://acm.fzu.edu.cn/problem.php?pid=1675
首先必须知道一点数论的基本公式 (a-b) %c =0 -----> a%c=b%c
首先通过大数取余求出目标数值对77的余数,然后求出要求数值之后开始到最后的数值对于77取余得到的余数,满足条件然后输出结果;进行枚举就可以了。
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<bitset> #include<iomanip> using namespace std; double num[]={1.0,10.0,100.0,1000.0,10000.0,100000.0,1000000.0,10000000.0,100000000.0,1000000000.0,10000000000.0, 100000000000.0,1000000000000.0,10000000000000.0,100000000000000.0,1000000000000000.0}; int main() { __int64 i , j , k , x , y , len , temp , sum , sum1 , sum2 , sum3 ; char str[ 1000005 ] ; while( scanf( "%s" , str ) != EOF ) { len = strlen( str ) ; sum = sum2 = 0 ; for( i = 0 ; str[ i ] ; ++i ) { if( str[ i ] == 'x' ) { sum = ( sum * 100 + 99 ) % 77 ; break ; } sum = sum * 10 + ( str[ i ] - '0' ) ; sum %= 77 ; printf( "%c" , str[ i ] ) ; } for( j = i + 4 ; str[ j ] ; ++j ) { sum2 = sum2 * 10 + ( str[ j ] - '0' ) ; sum2 %= 77 ; } temp = len - i - 4 ; for( k = 23 ; k <= 99 ; ++k ) { sum1 = ( sum * 100 + k ) % 77 ; for( x = 0 ; x <= temp / 15 + 1 ; ++x ) { sum1 = sum1 * num[ 15 ] ; sum1 %= 77 ; } sum1 = sum1 * num[ temp % 15 ] + sum2 ; sum1 %= 77 ; if( sum1 == 0 ) break ; } printf( "99%d" , k ) ; for( y = i + 4 ; str[ y ] ; y++ ) printf( "%c" , str[ y ] ) ; printf( "\n" ); } return 0 ; }