2016年湖南省第十二届大学生计算机程序设计竞赛 A. 2016(数学)

传送门

问题 A: 2016

问题 A: 2016

时间限制: 5 Sec   内存限制: 128 MB
提交: 248   解决: 137
[ 提交][ 状态][ 讨论版]

题目描述

 给出正整数 n 和 m,统计满足以下条件的正整数对 (a,b) 的数量:

1. 1≤a≤n,1≤b≤m;

2. a×b 是 2016 的倍数。

输入

输入包含不超过 30 组数据。

每组数据包含两个整数 n,m (1≤n,m≤10 9).

输出

对于每组数据,输出一个整数表示满足条件的数量。

样例输入


32 63 
2016 2016
1000000000 1000000000

样例输出


1 
30576
7523146895502644

解题思路:

首先我们对 2016 取模,也就是说 1 2017 是一样的, 2 2018 是一样的。所以我们可以用一个数组 mod[i] : 表示第 1 个数选 i 的时候,

第二个数有 mod[i] 种方案, 1i2016 ,因为 上面说了 1 2017 是等价的,所以通过这个我们就可以 yy 了,现在我们可以两重循环(是从 1 2016

把可能的数都算出来,固定一个 n 来算 m,具体可以参考代码,最后在算一个从 1 n % 2016 的循环就行了,每次加上  mod[i]

My Code

/**
2016 - 09 - 03 晚上
Author: ITAK

Motto:

今日的我要超越昨日的我,明日的我要胜过今日的我,
以创作出更好的代码为目标,不断地超越自己。
**/

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int INF = 1e9+5;
const int MAXN = 1e5+5;
const int MOD = 2016;
const double eps = 1e-7;
const double PI = acos(-1);
using namespace std;
LL Scan_LL()///输入外挂
{
    LL res=0,ch,flag=0;
    if((ch=getchar())=='-')
        flag=1;
    else if(ch>='0'&&ch<='9')
        res=ch-'0';
    while((ch=getchar())>='0'&&ch<='9')
        res=res*10+ch-'0';
    return flag?-res:res;
}
int Scan_Int()///输入外挂
{
    int res=0,ch,flag=0;
    if((ch=getchar())=='-')
        flag=1;
    else if(ch>='0'&&ch<='9')
        res=ch-'0';
    while((ch=getchar())>='0'&&ch<='9')
        res=res*10+ch-'0';
    return flag?-res:res;
}
void Out(LL a)///输出外挂
{
    if(a>9)
        Out(a/10);
    putchar(a%10+'0');
}
int mod[MAXN];
int main()
{
    int n, m;
    while(~scanf("%d%d",&n,&m))
    {
        memset(mod, 0, sizeof(mod));
        int tn = n/MOD, tm=m/MOD, ym = m%MOD;
        LL sum1 = 0, sum2 = 0;
        for(int i=1; i<2017; i++)
        {
            for(int j=1; j<2017; j++)
            {
                if(i*j%MOD == 0)
                {
                    if(MOD*tn+j <= n)
                        mod[i] = mod[i]+tn+1;
                    else
                        mod[i] += tn;
                }
            }
            sum1 += (LL)mod[i]*(LL)tm;
        }
        for(int i=1; i<=ym; i++)
            sum2 = sum2 + mod[i];
        cout<<sum1+sum2<<endl;
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值