UVALive 6173 Casting

题目链接:点击打开链接

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 10000005;
char s[N];

int main() {
	int T, cas, k;
	scanf("%d", &T);
	while(T-- > 0) {
		scanf("%d %d %s", &cas, &k, s);
		int n = strlen(s);
		int sum = 0;
		for(int i = 0; i < n; i ++) {
			sum = sum * k + s[i]- '0';
			sum %= (k-1);
		}
		printf("%d %d\n", cas, sum);
	}
	return 0;
}


你可能感兴趣的:(UVALive 6173 Casting)