zoukankan      html  css  js  c++  java
  • 2018(容斥定理 HDU6286)

    2018

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 507    Accepted Submission(s): 263

    Problem Description

    Given a,b,c,d, find out the number of pairs of integers (x,y) where a≤x≤b,c≤y≤d and x⋅y is a multiple of 2018.

    Input

    The input consists of several test cases and is terminated by end-of-file.

    Each test case contains four integers a,b,c,d.

    Output

    For each test case, print an integer which denotes the result.
    ## Constraint
    * 1≤a≤b≤109,1≤c≤d≤109
    * The number of tests cases does not exceed 104.

    Sample Input

    1 2 1 2018

    1 2018 1 2018

    1 1000000000 1 1000000000

    Sample Output

    3

    6051

    1485883320325200


    思路:

    1.若x是偶数:1)若x是1009的倍数,则y可为[c,d]中任意数; 2)若x不是1009的倍数,则y必定为[c,d]中1009的倍数
    2.若x是奇数:1)若x是1009的倍数,则y必定为[c,d]中2的倍数; 2)若x不是1009的倍数,则y必定为[c,d]中2018的倍数

    AC代码:

    #include<stdio.h>
    #include<iostream>
    #include<string.h>
    #include<algorithm>
    #include<math.h>
    #include<string>
    #include<queue>
    #include<utility>
    #define ll long long
    using namespace std;
    const int maxn = 1e5+7;
    
    int main(int argc, char const *argv[])
    {
        ll a,b,c,d;
        while(~scanf("%lld %lld %lld %lld",&a,&b,&c,&d))
        {
            ll s1 = b-a+1;
            ll s2 = d-c+1;
            ll s1_odd = b/2-(a-1)/2;
            ll s1_1009 = b/1009-(a-1)/1009;
    
            ll x1=(b/2018-(a-1)/2018)*s2;
            ll x2=(s1_odd-(b/2018-(a-1)/2018))*(d/1009-(c-1)/1009);
            ll x3=(s1_1009-(b/2018-(a-1)/2018))*(d/2-(c-1)/2);
            ll x4=((s1-s1_odd)-(s1_1009-(b/2018-(a-1)/2018)))*(d/2018-(c-1)/2018);
            printf("%lld\n",x1+x2+x3+x4);
        }
        return 0;
    }   
  • 相关阅读:
    Linux curl使用简单介绍
    SecureCRT编码转换vim
    BigTable/HBase基本概念解读 & Hbase shell常用命令
    Crontab用法说明(Linux)
    Sina SSO 登陆过程分析
    浅谈队列
    搞怪的 log4net 记录日志 性能测试
    iBatis.Net异步多线程 操作Ibatis报错
    高并发高负载的大型网站系统架构
    [置顶] IIs Web 站点安全 监控 站点自动部署 重启
  • 原文地址:https://www.cnblogs.com/chr1stopher/p/10299482.html
Copyright © 2011-2022 走看看