zoukankan      html  css  js  c++  java
  • CCPC2018-湖南全国邀请赛 K 2018

    K.2018

    题目描述

    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.

    输入

    The input consists of several test cases and is terminated by end-of-file.
    Each test case contains four integers a, b, c, d 

    输出

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

    样例输入

    1 2 1 2018
    1 2018 1 2018
    1 1000000000 1 1000000000
    

    样例输出

    3
    6051
    1485883320325200
     
    题意:给定区间[a,b]、[c,d],问有多少对有序数组(x,y)(x∈[a,b],y∈[c,d])使得x*y是2018的倍数
    思路:2018=2*1009(分解质因数),则对x分类讨论:1)仅为2的倍数;2)仅为1009的倍数;3)即为2又为1009的倍数;4)既不为2又不为1009的倍数
    等价于如下分类讨论:
    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的倍数

    #include <iostream>
    #include<cstring>
    #include<string>
    #include<cstdio>
    #include<algorithm>
    #include<cmath>
    #define ll long long
    using namespace std;
    int main()
    {
        ll a,b,c,d;
        while(cin>>a>>b>>c>>d)
        {
            ll s1=b-a+1;
            ll s2=d-c+1;
            ll s1_o=b/2-(a-1)/2;
            ll s1_1009=b/1009-(a-1)/1009;
    
            /*int x=b/2018-(a-1)/2018;
            ans+=x*s2;
    
            x=s1_o-x;
            ans+=x*(d/1009-(c-1)/1009);
    
            x=s1_1009-(b/2018-(a-1)/2018);
            ans+=x*(d/2-(c-1)/2);
    
            x=s1-s1_o-x;
            ans+=x*(d/2018-(c-1)/2018);*/
            ll x1,x2,x3,x4;
    
            x1=(b/2018-(a-1)/2018)*s2;
            x2=(s1_o-(b/2018-(a-1)/2018))*(d/1009-(c-1)/1009);
            x3=(s1_1009-(b/2018-(a-1)/2018))*(d/2-(c-1)/2);
            x4=((s1-s1_o)-(s1_1009-(b/2018-(a-1)/2018)))*(d/2018-(c-1)/2018);
            printf("%lld
    ",x1+x2+x3+x4);
        }
        return 0;
    }


  • 相关阅读:
    virtualenv与virtualenvwrapper
    数据类型、变量定义、数据类型转换
    计算机存储单元、标识符
    html单页面中用angular js
    svn客户端访问失败,错误“请求的名称有效,但是找不到请求的类型”的解决
    php 获取某数组中出现次数最多的值(重复最多的值)与出现的次数
    数据库导入时出现“2006
    phpstorm 激活
    取消本地SVN文件夹与服务器的关联
    js实现倒计时函数
  • 原文地址:https://www.cnblogs.com/caiyishuai/p/9062158.html
Copyright © 2011-2022 走看看