【数论】2016中国大学生程序设计竞赛 - 网络选拔赛 A. A water problem (大整数取模)

链接:http://acm.hdu.edu.cn/showproblem.php?pid=5832

题意:两个星球,一个星球一年只有137天,一个星球一年只有73天

输入N(爆炸后第N天),判断这是否为这两个星球的第一天

只要这个数是137与73的公倍数就好了(0比较特殊)

坑点:N的长度不超过10000000

只能用字符串来存储

大整数整除:紫书P314

大整数整除:首先把大整数写成“自左向右”的形式:1234 = (((1*10)+2)*10+3)*10+4

      然后每步取模

代码

1 char n[10000010];
2 int m;
3 scanf("%s %d",n,&m);   // n 存储大整数
4 int len = strlen(n);
5 int ans = 0;
6 for(int i = 0;i < len;i++)
7      ans = (int)(((long long)ans*10+n[i]-‘0‘)%m);
8 printf("%d\n",ans);

代码:

 1 #include <string>
 2 #include <cstdio>
 3 #include <iostream>
 4
 5 using namespace std;
 6
 7 const int m = 137*73;
 8 char n[10000010];
 9 int main()
10 {
11     int ca = 1;
12     while(~scanf("%s",n))
13     {
14         int ans = 0;
15         int len = strlen(n);
16         for(int i = 0;i < len;i++)
17             ans = (int)(((long long)ans*10+n[i]-‘0‘)%m);
18         if(ans == 0)
19             printf("Case #%d: YES\n",ca++);
20         else
21             printf("Case #%d: NO\n",ca++);
22     }
23
24     return 0;
25 }

原文地址:https://www.cnblogs.com/duny31030/p/8835378.html

时间: 2024-08-28 23:02:05

【数论】2016中国大学生程序设计竞赛 - 网络选拔赛 A. A water problem (大整数取模)的相关文章

2016中国大学生程序设计竞赛 - 网络选拔赛

solved 4/11 2016中国大学生程序设计竞赛 - 网络选拔赛

HDU 5833 Zhu and 772002(高斯消元)——2016中国大学生程序设计竞赛 - 网络选拔赛

传送门 Zhu and 772002 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 48    Accepted Submission(s): 16 Problem Description Zhu and 772002 are both good at math. One day, Zhu wants to test the abili

HDU 5832 A water problem(取模~)—— 2016中国大学生程序设计竞赛 - 网络选拔赛

传送门 A water problem Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 60    Accepted Submission(s): 37 Problem Description Two planets named Haha and Xixi in the universe and they were created wit

2016中国大学生程序设计竞赛 - 网络选拔赛 C. Magic boy Bi Luo with his excited tree

Magic boy Bi Luo with his excited tree Problem Description Bi Luo is a magic boy, he also has a migic tree, the tree has N nodes , in each node , there is a treasure, it's value is V[i], and for each edge, there is a cost C[i], which means every time

2016中国大学生程序设计竞赛 - 网络选拔赛 1004 Danganronpa

Problem Description Chisa Yukizome works as a teacher in the school. She prepares many gifts, which consist of n kinds with a[i] quantities of each kind, for her students and wants to hold a class meeting. Because of the busy work, she gives her gift

2016中国大学生程序设计竞赛 - 网络选拔赛 1011 Lweb and String

题目链接:http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1011&cid=719 Sample Input 2 aabcc acdeaa Sample Output Case #1: 3 Case #2: 4 *************************************************** 题意:我只能说题意神马都是浮云,纯属干扰,直接看代码吧 1 #include<stdio.h> 2 #i

【STL】【HDU5842】2016中国大学生程序设计竞赛 - 网络选拔赛 K. Lweb and String (set)(水~~~)

链接:http://acm.hdu.edu.cn/showproblem.php?pid=5842 水题,可以用来练习STL中的set 题目大意:给你一串字符串,字符串中的某个字母可以替换为一个数字,求最长上升子序列 例如: aabcdef --> 1123456 acdeaa  --> 123411    aabcc    --> 11233    dacbdda--> 1234112 红色字体为最长上升子序列 所以我们只需要统计有多少种不同的字母便可以得到答案 代码:(set解

2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6154 CaoHaha&#39;s staff 思维

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6154 题意:在笛卡尔坐标系下,画一个面积至少为  n 的简单多边形,每次只能画一条边或者一个格子的对角线,问至少要画几条. 解法:如果一个斜着的矩形长宽分别是 a,b,那么它的面积是 2ab.最优解肯定是离 sqrt(n/2)很近的位置.想想 n=5 时答案为什么是7 然后在那个小范围内枚举一下就好了.我给一张做题时画的图 #include <bits/stdc++.h> using namesp

2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6154 CaoHaha&#39;s staff(几何找规律)

Problem Description "You shall not pass!"After shouted out that,the Force Staff appered in CaoHaha's hand.As we all know,the Force Staff is a staff with infinity power.If you can use it skillful,it may help you to do whatever you want.But now,hi