zoukankan      html  css  js  c++  java
  • Casting

    Casting
    Time Limit: 3000ms, Special Time Limit:7500ms, Memory Limit:65536KB
    Total submit users: 23, Accepted users: 23
    Problem 12598 : No special judgement
    Problem description
    Casting around for problems leads us to combine modular arithmetic with different integer bases, particularly the problem of computing values modulo b - 1, where b is the base in which the value is represented. For example, 
    782910 mod 9 = 8 
    377777777777777738 mod 7 = 6 
    1234567 mod 6 = 3 
    (Note that 377777777777777738 = 112589990684261910 and 1234567 = 2287510.) 
    Your job is to write a program that reads integer values in various bases and computes the remainder after dividing these values by one less than the input base.



    Input
    The first line of input contains a single integer P, (1 ≤ P ≤ 1000), which is the number of data sets that follow. Each data set should be processed identically and independently. 
    Each data set consists of a single line of input containing three space-separated values. The first is an integer which is the data set number. The second is an integer which is the number, B (2 ≤ B ≤ 10), denoting a numeric base. The third is an unsigned number, D, in base B representation. For this problem, the number of numeric characters in D will be limited to 10,000,000. 


    Output
    For each data set there is a single line of output. It contains the data set number followed by a single space which is then followed by the remainder resulting from dividing D by (B - 1 ). 


    Sample Input
    5
    1 10 7829
    2 7 123456
    3 6 432504023545112
    4 8 37777777777777773
    5 2 10110100010101010101101110001010001010101010101010111
    
    
    Sample Output
    1 8
    2 3
    3 1
    4 6
    5 0
    
    Problem Source
    Greater New York Programming Contest 2012
     1 #include <cstdio>
     2 #include <cstring>
     3 #include <cmath>
     4 using namespace std;
     5 char a[10000000+10];
     6 int main(void){
     7 #ifndef ONLINE_JUDGE
     8   freopen("in", "r", stdin);
     9 #endif
    10   int t; scanf("%d", &t);
    11   while (t--){
    12     int s, b; scanf("%d%d%s", &s, &b, a);
    13     int len = strlen(a), po = 1, temp = 0;
    14     for (int i = len-1; i >= 0; --i){
    15       temp += (a[i]-'0') * po; temp %= (b-1);
    16     }
    17     printf("%d %d\n", s, temp);
    18   }
    19 
    20   return 0;
    21 }

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

  • 相关阅读:
    JS运行机制之 Event Loop 的思考
    模块机制 之commonJs、node模块 、AMD、CMD
    git报错:'fatal:remote origin already exists'怎么处理?附上git常用操作以及说明。
    Uncaught RangeError: Maximum call stack size exceeded-栈溢出
    对循环内部反复声明变量的写法的一点想法?
    JS的forEach和map方法的区别
    函数的属性和方法之call、apply 及bind
    利用Apach ab对nodejs进行并发负载的压力测试
    怎么判断一个对象是不是数组类型?
    Python模块学习之fabric
  • 原文地址:https://www.cnblogs.com/liuxueyang/p/2952784.html
Copyright © 2011-2022 走看看