A water problem 大整数取模

A water problem

Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 5814    Accepted Submission(s): 1238

Problem Description

Two planets named Haha and Xixi in the universe and they were created with the universe beginning.

There is 73 days in Xixi a year and 137 days in Haha a year.

Now you know the days N after Big Bang, you need to answer whether it is the first day in a year about the two planets.

Input

There are several test cases(about 5 huge test cases).

For each test, we have a line with an only integer N(0≤N), the length of N is up to 10000000.

Output

For the i-th test case, output Case #i: , then output "YES" or "NO" for the answer.

Sample Input

10001
0
333

Sample Output

Case #1: YES
Case #2: YES
Case #3: NO

#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn=1e8+5;
char s[maxn];
int ans,c;

int main(){
    while(~scanf("%s",s)){
        ans=0;
        int len=strlen(s);
        for(int i=0;i<len;i++)
            ans=(ans*10+s[i]-‘0‘)%10001;
        if(!ans){
            printf("Case #%d: YES\n",++c);
        }
        else printf("Case #%d: NO\n",++c);
    }

}

Statistic | Submit | Clarifications | Back

时间: 2024-12-22 19:11:37

A water problem 大整数取模的相关文章

【数论】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

Big Number(大整数取模)

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 Description As we know, Big Number is always troublesome. But it's really important in ou

poj2305-Basic remains(进制转换 + 大整数取模)

进制转换 + 大整数取模一,题意: 在b进制下,求p%m,再装换成b进制输出. 其中p为b进制大数1000位以内,m为b进制数9位以内二,思路: 1,以字符串的形式输入p,m; 2,转换:字符串->整数 十进制->b进制; 3,十进制下计算并将整形结果转换成字符串形式,并倒序储存; 4,输出.三,步骤: 1,输入p[],m[]; 2,字符串->整形 + 进制->b进制: i,进制转换语句:m2 = m2*b + m[j]-'0'; ii,大整数取模,大整数可以写成这样的形式: 12

大整数取模运算出现运算结果负数的解决方案

首先我们看个例子 <?php echo 12121212121 % 1000000; //结果为 -689767 //实际应该为12121 ?> 这里的取模运算(取余数)出现了BUG.那么需要声明一下,负数也是可以取模操作的,并不是出现负数就是不对的我们应该把这种长整数类型看成float型数据进行处理介绍一个函数float fmod ( float $x , float $y )返回除法的浮点数余数通过这个函数的运算,就可以得到原本想要的余数结果 <?php $a = floatval(

HDU 5832 A water problem 【大数取模,Java 大数也不是万能的。。】

A water problem Description Two planets named Haha and Xixi in the universe and they were created with the universe beginning. There is 73 days in Xixi a year and 137 days in Haha a year. Now you know the days N after Big Bang, you need to answer whe

【HDU 5832】A water problem(大数取模)

1千万长度的数对73和137取模.(两个数有点像,不要写错了) 效率要高的话,每15位取一次模,因为取模后可能有3位,因此用ll就最多15位取一次. 一位一位取模也可以,但是比较慢,取模运算是个耗时的运算. #include <cstdio> #define ll long long ll n,m; int p,cas; char s[10000005]; int main() { while(gets(s)){ n=m=p=0; while(s[p]){ for(int i=0;i<1

FZU 1759-Super A^B mod C(快速幂+大整数取模+欧拉函数)

题目链接:点击打开链接 题意:计算 a^b %c 但其中b很大,可能会达到10^1000000, 故有降幂公式 a^b %c= a^(b%phi(c)+phi(c)) %c  (b>=phi(c)) #include <algorithm> #include <iostream> #include <cstring> #include <cstdlib> #include <string> #include <cctype> #

大整数取模,秦九韶

#include <stdio.h> #include <string.h> #define MAXN 1000005 char s[MAXN]; int main () { int t; scanf("%d",&t); while(t--) { getchar(); int mod; scanf("%d",&mod); scanf("%s",s); int len = strlen(s); int ans

大整数取模

#include<cstdio> #include<cstdlib> #include<cstring> #define N 10000 int main() {     char str[N];     int len;int i;     int mod;     int ans=0;     int Case;     scanf("%d",&Case);     while(Case--){     scanf("%s&qu