Hdu1212 big number [same theorem]

Source: Internet
Author: User

Big numbertime limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others) Total submission (s): 4594 accepted submission (s): 3175

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

Use the same remainder theorem: (a + B) % C = (a % C + B % C) % C = (a + B % C) % C; Appendix: (A * B) % C = (a % C * B % C) % C;

#include <stdio.h>#define maxn 1002char str[maxn];int main(){    int m, ans, i;    while(scanf("%s%d", str, &m) != EOF){        ans = 0;        for(i = 0; str[i]; ++i){            ans = (ans * 10 + (str[i] - '0') % m) %m;        }        printf("%d\n", ans);    }    return 0;}


Hdu1212 big number [same theorem]

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.