Big number (Modulo of big integers)

Source: Internet
Author: User
Tags integer division
Big number Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 4789 accepted submission (s): 3329


Problem descriptionas we know, big number is always troublesome. But it's really important in our ACM. And today, your task is to write a program to calculate a mod B.

To make the problem easier, I promise that B will be smaller than 100000.

Is it too hard? No, I work it out in 10 minutes, and my program contains less than 25 lines.
 
Inputthe input contains several test cases. each test case consists of two positive integers A and B. the length of a will not exceed 1000, and B will be smaller than 100000. process to the end of file.
 
Outputfor each test case, You Have To ouput the result of a mod B.
 
Sample Input
2 312 7152455856554521 3250
 
Sample output
251521
 
Authorignatius. L
Source hangdian ACM provincial training team trials

Meaning: Big integer modulo operation, similar to integer division (hand calculation), for example, 512% 10, we have 51% 10 = 1, and then 1*10 + 2 = 12, in 12% 10 = 2, it is over;
AC code:
#include <iostream>#include <cstring>#include <cstdio>#include <cmath>using namespace std;typedef long long ll;int main(){    char s[1100];    int mod,len;    while(cin>>s>>mod)    {        ll sum = 0;        len = strlen(s);        for(int i = 0; i < len; i++)        {            sum = (sum * 10 + s[i] - '0') % mod;        }        cout<<sum<<endl;    }    return 0;}


Big number (Modulo of big integers)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.