惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

云风的 BLOG
云风的 BLOG
Blog — PlanetScale
Blog — PlanetScale
博客园 - 【当耐特】
博客园_首页
The GitHub Blog
The GitHub Blog
月光博客
月光博客
Hugging Face - Blog
Hugging Face - Blog
有赞技术团队
有赞技术团队
博客园 - 三生石上(FineUI控件)
D
Docker
Stack Overflow Blog
Stack Overflow Blog
WordPress大学
WordPress大学
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Apple Machine Learning Research
Apple Machine Learning Research
Vercel News
Vercel News
酷 壳 – CoolShell
酷 壳 – CoolShell
雷峰网
雷峰网
小众软件
小众软件
I
InfoQ
A
About on SuperTechFans
T
The Blog of Author Tim Ferriss
S
SegmentFault 最新的问题
Microsoft Azure Blog
Microsoft Azure Blog
博客园 - Franky

OhYee 博客

小鹏辅助驾驶测评|OhYee 博客 小鹏非支持手机开启自动解锁|OhYee 博客 使用函数计算实现 301 重定向|OhYee 博客 针对 HTML 内容使用 Ant Design 图片弹框|OhYee 博客 博客进程泄露及僵尸进程解决|OhYee 博客 蓝易云服务器体验|OhYee 博客 SSH 调起本地 VSCode|OhYee 博客 【2022 秋招内推】阿里云后端研发工程师|OhYee 博客 使用函数计算获取 IP 地址信息|OhYee 博客 正确获取客户端 IP/HTTP Header 也可能重复|OhYee 博客 评测 Oculus Quest2 及 BigScreen|OhYee 博客 NextJS 热重载保留状态|OhYee 博客 如何优雅地贴 gist 代码|OhYee 博客 Linux 精细化文件权限|OhYee 博客 VSCode 容器开发环境|OhYee 博客 Clash 的不兼容更新排查|OhYee 博客 Zeek 导出 PCAP|OhYee 博客 记一次 ssh 配置问题|OhYee 博客 Git Commit 规范化工具|OhYee 博客 谈谈《星之卡比-探索发现》|OhYee 博客 VSCode 快捷键绑定 Shell 命令|OhYee 博客 ASN.1 语法及 X.509 证书格式解析解析|OhYee 博客 腾讯企业邮箱忽略 MX 记录发信|OhYee 博客 Chrome/Edge 标签组插件|OhYee 博客 【应届内推】阿里云后端研发工程师|OhYee 博客 损坏的 Typecho 备份处理为 JSON|OhYee 博客 VS Code VIM 插件高效使用|OhYee 博客 SSH 正反向代理|OhYee 博客 Let's Encrypt 根证书过期引发的问题|OhYee 博客 OpenWRT 忽略内核依赖|OhYee 博客
HDU 5832.A water problem|OhYee 博客
2016-08-14 · via OhYee 博客

这是一篇最后编辑于 8 年前 的文章,其内容可能与目前实际情况差异较大,请注意甄别

题目

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

题解

求两个公转周期分别为 73137 的星球在第 i 天是否都是新年第一天
也即 i%73i%137 是否都为 0

由于输入数据最大为 10000000
因此需要 高精度算法

高精度读入后取余即可

由于数组较大,直接套用模板的高精度可能会因为构造函数爆掉
因此应该自己写读入部分
(数据貌似有前导 0 )

代码

/*
By:OhYee
Github:OhYee
Blog:http://www.oyohyee.com/
Email:oyohyee@oyohyee.com

かしこいかわいい?
エリ0隶�
要写出来Хорошо的代码哦~
*/
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <bitset>
#include <iomanip> 
using namespace std;

const int maxn = 10000005;
int kase = 0;

/*
* 完全大数模板
* 输出cin>>a
* 输出a.print();
* 注意这个输入不能自动去掉前导0的,可以先读入到char数组,去掉前导0,再用构造函数。
*/
#define MAXN 9999
#define MAXSIZE 1010
#define DLEN 4
struct BigInter {
    int a[maxn]; //可以控制大数的位数
    int len;
    BigInter() {
        len = 1; memset(a,0,sizeof(a));
    } //构造函数
    BigInter(const char*); //将一个字符串类型的变量转化为大数
    int operator % (const int &)const; //大数对一个int类型的变量进行取模运算
    void print(); //输出大数
    void read(const char *s);
};
BigInter::BigInter(const char *s) //将一个字符串类型的变量转化为大数
{
    int t,k,index,L,i;
    memset(a,0,sizeof(a));
    L = strlen(s);
    len = L / DLEN;
    if(L%DLEN)len++;
    index = 0;
    for(i = L - 1; i >= 0; i -= DLEN) {
        t = 0;
        k = i - DLEN + 1;
        if(k < 0)k = 0;
        for(int j = k; j <= i; j++)
            t = t * 10 + s[j] - '0';
        a[index++] = t;
    }
}
int BigInter::operator % (const int &b)const //大数对一个 int类型的变量进行取模
{
    int i,d = 0;
    for(i = len - 1; i >= 0; i--)
        d = ((d*(MAXN + 1)) % b + a[i]) % b;
    return d;
}
void BigInter::print() //输出大数
{
    int i;
    printf("%d",a[len - 1]);
    for(i = len - 2; i >= 0; i--)
        printf("%04d",a[i]);
    printf("\n");
}
void BigInter::read(const char *s) {
    int t,k,index,L,i;
    memset(a,0,sizeof(a));
    L = strlen(s);
    len = L / DLEN;
    if(L%DLEN)len++;
    index = 0;
    for(i = L - 1; i >= 0; i -= DLEN) {
        t = 0;
        k = i - DLEN + 1;
        if(k < 0)k = 0;
        for(int j = k; j <= i; j++)
            t = t * 10 + s[j] - '0';
        a[index++] = t;
    }
}

BigInter ans;
char s[maxn];

bool Do() {
    if(scanf("%s",s) == EOF)
        return false;
    
    printf("Case #%d: ",++kase);
    
    int pos = 0;
    int len = strlen(s);
    for(int i = 0;i < len;i++) {
        if(s[i] != '0') {
            pos = i;
            break;
        }
    }
    for(int i = pos;i < len;i++)
        s[i - pos] = s[i];
    s[len - pos] = '\0';
    
    ans.read(s);
    
    if(ans % 73 == 0 && 0 == ans % 137)
        printf("YES\n");
    else
        printf("NO\n");


    return true;
}

int main() {
    cin.tie(0);
    cin.sync_with_stdio(false);
    while(Do());
    return 0;
}