问题 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
和
第二个数有
mod[i]
种方案,
1≤i≤2016
,因为 上面说了
1
和
把可能的数都算出来,固定一个
n
来算
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;
}