当前位置: 代码迷 >> 综合 >> HDU - 1212 -Big Number
  详细解决方案

HDU - 1212 -Big Number

热度:14   发布时间:2024-01-08 23:50:27.0

As 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.

Input
The 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.

Output
For each test case, you have to ouput the result of A mod B.

Sample Input
2 3
12 7
152455856554521 3250

Sample Output
2
5
1521

#include"stdio.h"
#include "string.h"
#include "math.h"
int main()
{char ai[1000];_int64 B,n,num,yu,i,j;while(scanf("%s",ai)==1){getchar();scanf("%I64d",&B);yu=0;n=strlen(ai);   for (i=0;i<=n-6;i=i+6){num=yu*1000000+(ai[i]-48)*100000+(ai[i+1]-48)*10000+(ai[i+2]-48)*1000+(ai[i+3]-48)*100+(ai[i+4]-48)*10+ai[i+5]-48;yu=num%B;}num=0;for(j=i;j<n;j++){num=num+(ai[j]-48)*pow(10,(n-j-1));}num=num+yu*pow(10,(n-i));printf("%I64d\n",num%B);        }return 0;
}
  相关解决方案