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

题目连接:

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

题意

给你一个数,问你这个数是否能够整除137和73

题解:

这两个数互质,其实就是问你能否整除10001(73*137,)

这个直接扫一遍就好了。

用string可能会TLE,所以老老实实用char就好了

Java 都是 MLE,看来Java也不是万能的,

AC代码:

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
char a[10000005];
int main()
{
    int kase=0;
    int n;
    //freopen("data/5832.txt","r",stdin);
    while(cin>>a)
    {
        printf("Case #%d: ",++kase);
        int len=strlen(a);
        int mod=0;
        for(int i=0;i<len;i++)
        {
            mod=(mod*10+a[i]-'0')%10001;
        }
        if(mod==0)
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
    }
    return 0;
}

Java MLE 代码:

import java.math.BigInteger;
import java.util.Scanner;
public class Main {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner sc = new Scanner(System.in);
        int kase = 0;
        while(sc.hasNext()){
            BigInteger a = sc.nextBigInteger();
            BigInteger mod = BigInteger.valueOf(10001);
            BigInteger ans = a.mod(mod);
            System.out.printf("Case #%d: ",++kase);
            if(ans.equals(BigInteger.ZERO)){
                System.out.println("YES");
            }else{
                System.out.println("NO");
            }
        }
    }
}
时间: 2024-12-16 11:56:07

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

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

HDU 5832 A water problem (水题,大数)

题意:给定一个大数,问你取模73 和 137是不是都是0. 析:没什么可说的,先用char 存储下来,再一位一位的算就好了. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include <iostream>

HDU 1212 Big Number(C++ 大数取模)(java 大数类运用)

Big Number 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1212 --每天在线,欢迎留言谈论. 题目大意: 给你两个数 n1,n2.其中n1 很大很大,n1%n2的值. 知识点: ①秦九韶公式:例:1314= ((1*10+3)*10+1)*10+4 ②(a*b)%c == (a%c)*(b%c) .(a+b)%c == (a%c)+(b%c) . 思路: 每步取模即可. C++ AC代码: 1 #include <iostream>

HDU 5832 A water problem(某水题)

HDU 5832 A water problem(某水题) Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)   Problem Description - 题目描述 Two planets named Haha and Xixi in the universe and they were created with the universe beginning. There is

HDU 5832 A water problem

大数取模. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<vector> #include<map> #include<set> #include<queue> #in

HDU 5832 A water problem 大数取余

A water problem Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 650    Accepted Submission(s): 333 Problem Description Two planets named Haha and Xixi in the universe and they were created with

hdu2302(枚举,大数取模)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2303 题意:给出两个数k, l(4<= k <= 1e100, 2<=l<=1e6):其中k是两个素数的乘积,问k是否存在严格小于l的因子,若有,输出 BAD 该因子,反之输出GOOD: 思路: 先1e6内素数打表,再枚举一个因子,判断因子用大数取模: 代码: 1 #include <iostream> 2 #include <stdio.h> 3 #inclu

快速幂+大数取模

快速幂+大数取模 快速幂,其实就是求(a^b)% p,(其中a,b,p都比较大在int范围内)这类问题. 首先要知道取余的公式:(a*b)%p=(a%p*b%p)%p. 那么幂不就是乘机的累积吗,由此给出代码: int fast(int a,int b,int p) {   long long a1=a,t=1; while(b>0) { if(b&1)          /如果幂b是奇数多乘一次,因为后边会除2变偶数,(7/2=3) t=(t%p)*(a1%p)%p; a1=(a1%p)*

csu 1556: Jerry&#39;s trouble(大数取模)

题意:求出1^m+2^m+...n^m 思路:直接套用模板 #include<cstdio> #include<iostream> #include<cstring> #include<cmath> #include<stdlib.h> #include<algorithm> #include<queue> #include<stack> #include<ctype.h> #define LL l