本文共 1736 字,大约阅读时间需要 5 分钟。
#include #include #include #include #include #include #include #include #include #include #include #include #define MEM(x,y) memset ( x , y , sizeof ( x ) )#define rep(i,a,b) for (int i = a ; i <= b ; ++ i)#define per(i,a,b) for (int i = a ; i >= b ; -- i)#define pii pair < int , int >#define X first#define Y second#define rint read #define int long long#define pb push_backusing std::set ;using std::pair ;using std::max ;using std::min ;using std::priority_queue ;using std::vector ;using std::swap ;using std::sort ;using std::unique ;using std::greater ;template < class T > inline T read () { T x = 0 , f = 1 ; char ch = getchar () ; while ( ch < '0' || ch > '9' ) { if ( ch == '-' ) f = - 1 ; ch = getchar () ; } while ( ch >= '0' && ch <= '9' ) { x = ( x << 3 ) + ( x << 1 ) + ( ch - 48 ) ; ch = getchar () ; } return f * x ;}const int N = 100 ; bool mk[15] ;int n , m , T , tot ;vector < int > tmp ;signed main (int argc , char * argv[]) { T = rint () ; while ( T -- ) { n = rint () ; m = rint () ; tot = 0 ; int sum = 0 ; if ( m > n ) { puts ("0") ; continue ; } if ( n == m ) { printf ("%lld\n" , m % 10 ) ; continue ; } rep ( i , 0 , 10 ) mk[i] = false ; tmp.clear () ; while ( true ) { ++ tot ; int t = m * tot % 10 ; if ( mk[t] ) break ; tmp.pb ( t ) ; sum += t ; mk[t] = true ; } int rpt = ( n / m ) / (int)tmp.size () ; int ans = sum * rpt ; rep ( i , 0 , n / m % (int)tmp.size () - 1 ) ans += tmp[i] ; printf ("%lld\n" , ans ) ; } return 0 ;}
转载于:https://www.cnblogs.com/Equinox-Flower/p/11486593.html