Casting

March 10, 2013


#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
char a[10000000+10];
int main(void){
#ifndef ONLINE_JUDGE
  freopen("in", "r", stdin);
#endif
  int t; scanf("%d", &t);
  while (t--){
    int s, b; scanf("%d%d%s", &s, &b, a);
    int len = strlen(a), po = 1, temp = 0;
    for (int i = len-1; i >= 0; --i){
      temp += (a[i]-'0') * po; temp %= (b-1);
    }
    printf("%d %d\n", s, temp);
  }

  return 0;
}

求在某个进制的数字的余数,没卡。

comments powered by Disqus