2018 ccpc湘潭邀请赛 K. 2018 [思维+容赤]

25 篇文章 0 订阅

2018

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


Problem Description
Given  a,b,c,d, find out the number of pairs of integers  (x,y) where  axb,cyd and  xy 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

1ab109,1cd109
* 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
 

Source

签到题????2018 = 2×1009;很明显吗????

只要找两边2 , 1009,2×1009的个数容赤一下就好了。。。

代码 :

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 1e5+7;
ll prim[maxn], cas[maxn], numcas[maxn];
bool vis[maxn];
int cnt = 0, tot = 0;
ll a, b, c, d, a1, b1, c1, s1, a2, b2, c2, s;
void FIND(ll a)
{
    ll k = a;
    for(int i  = 0; i < cnt&&k > 1&&prim[i]*prim[i] <= k; i++)
    {
        if(k%prim[i] == 0)
        {
            cas[tot] = prim[i];
            while(k%prim[i] == 0)
            {
                k /= prim[i];
                numcas[tot]++;
            }
            tot++;
        }
    }
    if(k > 1) {
        cas[tot] = k;
        numcas[tot++] = 1;
    }
}


void print()
{
    for(int i = 0; i < tot; i++)
    {
        printf("%d %d\n", cas[i], numcas[i]);
    }
}

void init()
{
    memset(vis, 0, sizeof(vis));
    memset(cas, 0, sizeof(cas));
    memset(numcas, 0, sizeof(numcas));
    for(int i = 2; i*i < maxn; i++)
        if(!vis[i])
            for(int j = i*i; j < maxn; j+=i)
                vis[j] = true;
    for(int i = 2; i < maxn; i++)
        if(!vis[i]) prim[cnt++] = i;
    FIND(2018);
    print();
}




int main()
{
    //init();
    //freopen("in.txt", "r", stdin);
    while(~scanf("%lld%lld%lld%lld", &a, &b, &c, &d))
    {
        c1 = b/(2*1009) - (a - 1)/(2*1009);
        a1 = b/2 - (a - 1)/2 - c1;
        b1 = b/1009 - (a - 1)/1009 - c1;
        s1 = b - a + 1 - a1 - b1 - c1;
        c2 = d/(2*1009) - (c - 1)/(2*1009);
        a2 = d/2 - (c - 1)/2 - c2;
        b2 = d/1009 - (c - 1)/1009 - c2;
        s = d - c + 1;
        printf("%lld\n", a1*(b2+c2) + b1*(a2+c2) + c1*s + c2*s1);
    }
    return 0;
}

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值