2016-CSU1803(同余公式)

来源:互联网 发布:调用接口获取json数据 编辑:程序博客网 时间:2024/04/26 19:30

题目链接

题意:求满足a * b 是 2016的倍数的对数,  1<= a <=n, 1<= b <=m;

思路:定义一个数组,算出0-n对2016取余,数组中第i个数表示0-n之间对2016取余为i的个数。同理,对0-m也开一个数组处理。

          最后只需要算出两个数组的每个数相乘的和。

代码:

 /// He  renders  landscapes  with  great  skill  and  artistry.    #define _CRT_SECURE_NO_WARNINGS    #include <cstdio>    #include <cstring>    #include <iostream>    #include <algorithm>    #include <cstdlib>    #include <cmath>    #include <iterator>    #include <cctype>    #include <sstream>    #include <string>    #include <vector>    #include <set>    #include <map>    #include <stack>    #include <deque>    #include <queue>    #include <list>    #include <functional>    #include <ctime>    #include <bitset>    //#pragma comment(linker, "/STACK:102400000, 102400000")    #define debug     puts("+******************************************************+")    #define Min(a, b) ( (a < b) ? a : b )    #define Max(a, b) ( (a > b) ? a : b )    #define lc         o<<1    #define rc         o<<1|1    #define lson       L, M, lc    #define rson       M + 1, R, rc    #define mem0(x)   memset(x, 0, sizeof x)    #define mem1(x)   memset(x, -1, sizeof x)    #define memf(x)   memset(x, false, sizeof x)    #define pb        push_back    #define pf        push_front    #define LB        lower_bound    #define UB        upper_bound    #define PQ        priority_queue    #define fr(x)     freopen("x", "r", stdin )    #define fw(x)     freopen("x", "w" , stdout)    #define all(a)    a.begin(), a,end()    #define X         first    #define Y         second    #define MP        make_pair    #define Abs(x)    ( x >= 0 ) ? x : ( -x )    #define MAXS      50000 + 8    #define MAXT      10000 + 8    #define MAXL      500000 + 8    #define INF       0x3f3f3f3f    #define INFL      1000000000000000000    #define inf       -(1<<30)    #define EPS       1e-10    #define PI        acos(-1.0)    #define sqr(x)    (x * x)    using namespace std;    typedef long long          LL;    typedef unsigned long long uLL;    typedef double             DB;    typedef long double        LD;    typedef pair<int, int >   pii;    typedef pair<LL, LL>       pll;    const int MOD   = 1e9;    const int N     = 1e5 + 8;    const int maxn  = 1e3 + 8;    const int dx[]  = { -1, 1,  0, 0 };    const int dy[]  = {  0, 0, -1, 1 };    struct Node    {        LL x;        int id;        char ch;        bool operator < ( const Node & n) const        {            return x < n.x;        }    } no[N];    int t;    LL n, m;    LL a[2020], b[2020];    int main()    {        //freopen("codecoder.in", "r", stdin);        //freopen("out.txt", "w", stdout);        // ios::sync_with_stdio(false);        while (~scanf("%lld%lld", &n, &m)) {              LL ans = 0;              mem0(a);              mem0(b);              for (int i = 0; i < 2016; i++) {                   a[i] = n / 2016;                   b[i] = m / 2016;              }              for (int i = 1; i <= n % 2016; i++) a[i]++;              for (int i = 1; i <= m % 2016; i++) b[i]++;              for (int i = 0;  i < 2016; i++) {                   for (int j = 0 ; j < 2016; j++) {                         if ( i * j % 2016 == 0 )                            ans += (LL)a[i] * b[j];                   }              }              printf("%lld\n", ans);        }        return 0;    }


0 0
原创粉丝点击