1. 程式人生 > >Alyona and Numbers(數學水題)

Alyona and Numbers(數學水題)

題意分析:給定兩個數n,m, 1 <=  x <= n,   1 <= y <= m,求一共有多少個有序對(x, y)滿足(x + y) % 5 == 0,題意很簡單,直接上程式碼吧。

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<stack>
#include<set>
#include<queue>
#include<sstream>
using namespace std;
int main()
{   long long n,m,sum = 0;
    scanf("%I64d%I64d",&n,&m);
    long long ans1[10],ans2[10];
    long long nnum = n / 5, mnum = m / 5;
    for(int i = 0; i < 5; i++)
    {
        ans1[i] = nnum; ans2[i] = mnum;
        if(n % 5 >= i) ans1[i]++;
        if(m % 5 >= i) ans2[i]++;
    }
//   for(int i = 0; i < 5; i++)
//    cout << ans1[i] << "*****" << ans2[i] << "**\n";
    ans1[0]--; ans2[0]--;
    sum = ans1[0] * ans2[0] + ans1[1] * ans2[4] + ans1[2] * ans2[3] + ans1[3] * ans2[2] + ans1[4] * ans2[1];
     printf("%I64d\n",sum);
    return 0;
}