Big Number

来源:互联网 发布:看动漫学日语软件 编辑:程序博客网 时间:2024/04/29 02:31

Big Number

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5988    Accepted Submission(s): 4184


Problem Description
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 312 7152455856554521 3250
 

Sample Output
251521
C语言程序代码
/*解题思路::这是个大数题,要用数组。有数学上的一些规律即:(a+b)%c=(a%c+b%c)%c;a*b%c=(a%c*b%c)%c;所以根据这个就可以将大数变小, 用数组逐位取余即可,避免计算大数。 */#include<stdio.h>#include<string.h>#include<math.h>int main(){char s[100001];int a,n,m,sum,l,i;while(scanf("%s %d",s,&n)!=EOF){l=strlen(s);sum=0;for(i=0;i<l;i++)sum=(sum*10+(s[i]-'0')%n)%n;printf("%d\n",sum);}return 0;}
0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 开车堵在路上到了限行时间怎么办 兄妹之间都不想照顾母亲我该怎么办 小孩扁体发炎睡觉呼吸声沉重怎么办 客所思pk3老驱动有杂音怎么办 手机打不开解压包密码怎么办 在香港专柜买东西柜员少给货怎么办 恶魔猎手第二神器任务没选择怎么办 电脑放久了开不了机怎么办 你在主持时说错话了怎么办 1、你在主持时说错话了怎么办? 领导让你替他参加重要会议怎么办 在备孕期老公照了片怎么办 和混混打架后被混混纠缠怎么办 开了一年的瑜伽馆想关掉会员怎么办 广东工厂宿舍里面床板有臭虫怎么办 胃癌手术后12天引流液多怎么办 八个月了胎儿头还在上面怎么办 喂奶一个月后奶头又裂开了怎么办 孩子吃奶吃的奶头裂开了怎么办 很想打坐久就是受不了腿疼怎么办 宝宝含乳一直纠正不过来怎么办 婴儿衘乳不正确只吸乳头怎么办 怀孕7个月了晚上睡不着怎么办 尚德学校学费交了一半退学怎么办 随着年龄的增长胸越来越来小怎么办 运动文胸里边的海绵垫会乱跑怎么办 带胸罩时在外面忽然扣子开了怎么办 我的脸一边大一边小怎么办 桶装水盖子吸在饮水机了怎么办? 孕37周大腿内侧被内裤磨烂怎么办 生存指南合成的时候闪退怎么办 王者荣耀队友用语音骂我怎么办? 轨道衡电子计量数据不对上怎么办 孕5个月胎儿发育慢怎么办 扎高马尾后面头发扎不上去怎么办 吃了不太新鲜的肉怎么办 军训腿疼的蹲不下去怎么办 面对对老师不尊重的学生该怎么办? 当学生犯了错老师应该怎么办? 用木棒按摩脚底感觉有疙瘩怎么办 人流后按摩造成子宫复位不好怎么办