说实话,对于我这萌新来说真的难。。。。后面看了大牛的博客才懂的,就是n和m分别对2016取模,然后放到数组里存。
#include<iostream>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include <algorithm>
#pragma warning(disable:4996)
using namespace std;
long long a[2030], b[2030];
int main()
{
long long n, m;
int i, j;
long long k, t;
long long count;
while (~scanf("%lld%lld", &n, &m))
{
count = 0;
k = n / 2016;
t = n % 2016;
for (i = 1; i <= t; i++)
a[i] = k + 1;
for (i = t + 1; i <= 2016; i++)
a[i] = k;
k = m / 2016;
t = m % 2016;
for (i = 1; i <= t; i++)
b[i] = k + 1;
for (i = t + 1; i <= 2016; i++)
b[i] = k;
for (i = 1; i <= 2016; i++)
{
for (j = 1; j <= 2016; j++)
if ((i*j) % 2016 == 0)
count = cou + a[i] * b[j];
}
printf("%lld\n",count);
}
return 0;
}
以下的大牛代码,然而看不懂。。。。
#include<iostream>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include <algorithm>
#pragma warning(disable:4996)
using namespace std;
int n, m;
long long f(int g)
{
int nn = n / g;
long long s = nn - (1008 % g == 0)*nn / 2 - (672 % g == 0)*nn / 3 - (288 % g == 0)*nn / 7;
s += (336 % g == 0)*nn / 6 + (96 % g == 0)*nn / 21 + (144 % g == 0)*nn / 14 - (48 % g == 0)*nn / 42;
long long gg = g;
return gg*m / 2016 * s;
}
long long f7(int g)
{
return f(g) + f(g * 7);
}
long long f5(int g)
{
return f7(g) + f7(g * 3) + f7(g * 9);
}
int main()
{
while (cin >> n >> m)cout << f5(1) + f5(2) + f5(4) + f5(8) + f5(16) + f5(32) << endl;
return 0;
}