zoukankan      html  css  js  c++  java
  • sicily 1020. Big Integer

    Description

    Long long ago, there was a super computer that could deal with VeryLongIntegers(no VeryLongInteger will be negative). Do you know how this computer stores the VeryLongIntegers? This computer has a set of n positive integers: b1,b2,...,bn, which is called a basis for the computer.

    The basis satisfies two properties:
    1) 1 < bi <= 1000 (1 <= i <= n),
    2) gcd(bi,bj) = 1 (1 <= i,j <= n, i ≠ j).

    Let M = b1*b2*...*bn

    Given an integer x, which is nonegative and less than M, the ordered n-tuples (x mod b1, x mod b2, ..., x mod bn), which is called the representation of x, will be put into the computer.

    Input

    The input consists of T test cases. The number of test cases (T) is given in the first line of the input.
    Each test case contains three lines.
    The first line contains an integer n(<=100).
    The second line contains n integers: b1,b2,...,bn, which is the basis of the computer.
    The third line contains a single VeryLongInteger x.

    Each VeryLongInteger will be 400 or fewer characters in length, and will only contain digits (no VeryLongInteger will be negative).

    Output
    For each test case, print exactly one line -- the representation of x.
    The output format is:(r1,r2,...,rn)
     
    求一个大整数对N个数的模,其实关键就只有这两句代码
    for( i = 0; i < len; i++ )
        ans = ( ans * 10 + (x[i] - '0') ) % num;

    AC代码

    View Code
     1 #include <stdio.h>
     2 #include <string.h>
     3 int mod( char x[], int num )
     4 {
     5     int len = strlen(x);
     6     int ans = 0, i;
     7     
     8     for( i = 0; i < len; i++ )
     9         ans = ( ans * 10 + (x[i] - '0') ) % num;
    10     
    11     return ans;
    12 }
    13 
    14 int main()
    15 {
    16     int t, n, b[100], i;
    17     char x[401];
    18     
    19     scanf("%d", &t);
    20     while ( t-- )
    21     {
    22         scanf("%d", &n);
    23         
    24         for( i = 0; i < n; i++ )
    25             scanf("%d", &b[i]); 
    26            
    27            scanf("%s", x); 
    28        
    29         printf("(");
    30         for ( i = 0; i < n; i++ )
    31         {
    32             if ( i != n - 1 )
    33                 printf("%d,", mod(x, b[i]));
    34             else
    35                 printf("%d)\n", mod(x, b[i]));
    36         }
    37         
    38     }
    39 
    40     return 0;
    41 }
  • 相关阅读:
    NoSQL之Redis入门笔记
    运维甩锅神器---Jumpserver
    sersync+rsync=实时异步备份
    gitlab+jenkins=自动化构建
    python笔记07-----打包模块(shutil,zipfile,tarfile)
    python笔记06-----常用模块(time,os,sys,random)
    python笔记09-----装饰器,生成器,迭代器
    python笔记05-----函数
    机器学习3_EM算法与混合高斯模型
    机器学习2-极大似然估计与贝叶斯估计
  • 原文地址:https://www.cnblogs.com/joyeecheung/p/2877229.html
Copyright © 2011-2022 走看看