其实没有太难
但是不知道的话想不到
考场上大概有50分吧
1 #include <iostream> 2 #include <stdio.h> 3 #include <queue> 4 5 using namespace std; 6 7 int mod[7 + 2] = { 19 , 101 , 11261 , 19997 , 22877 , 21893 , 14843 }; 8 int n , m , ans[1000000 + 2]; 9 char a[100 + 10][10000 + 10]; 10 int i , j , k; 11 int power[1000000 + 2]; 12 int ver[7][1000000 + 2]; 13 queue < int > q; 14 int num; 15 16 bool check( int x ) 17 { 18 int i , j , flag = 0; 19 long long ans = 0; 20 power[0] = 1; 21 for( i = 1 ; i <= n ; i++ ) 22 power[i] = power[i - 1] * x % mod[k]; 23 for( i = 0 ; i <= n ; i++ ) 24 { 25 if( a[i][0] != ‘-‘ ) 26 ans += ver[k][i] * power[i]; 27 else 28 ans -= ver[k][i] * power[i]; 29 ans %= mod[k]; 30 } 31 while( ans < 0 ) 32 ans += mod[k]; 33 return !( ans % mod[k] ); 34 } 35 36 int main() 37 { 38 scanf( "%d %d" , &n , &m ); 39 for( i = 0 ; i <= n ; i++ ) 40 scanf( "%s" , a[i] ); 41 for( k = 0 ; k < 7 ; k++ ) 42 for( i = 0 ; i <= n ; i++ ) 43 for( j = 0 ; a[i][j] ; j++ ) 44 { 45 if( a[i][j] == ‘-‘ ) 46 continue; 47 ver[k][i] *= 10; 48 ver[k][i] += a[i][j] - ‘0‘; 49 ver[k][i] %= mod[k]; 50 } 51 for( k = 0 ; k < 7 ; k++ ) 52 for( i = 0 ; i < mod[k] && i <= m ; i++ ) 53 if( check( i ) ) 54 for( j = i ; j <= m ; j += mod[k] ) 55 ans[j]++; 56 for( i = 1 ; i <= m ; i++ ) 57 if( ans[i] == 7 ) 58 { 59 num++; 60 q.push( i ); 61 } 62 printf( "%d\n" , num ); 63 while( !q.empty() ) 64 printf( "%d\n" , q.front() ) , q.pop(); 65 return 0; 66 }
时间: 2024-10-26 18:08:36