• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
dwtfukgv
博客园    首页    新随笔    联系   管理    订阅  订阅
CodeForces 682A Alyona and Numbers (水题,数学)

题意:给定两个数 m,n,问你在从1到 n,和从 1到 m中任选两个数加起来是5的倍数,问你有多少个。

析:先计算 m 和 n中有多少个取模5是从0到4的,然后根据排列组合,相乘就得到了小于等于 m 和 n的并且能整除五的个数,然后再加上剩下的。

代码如下:

#include <bits/stdc++.h>

using namespace std;
typedef long long LL;
const int aa = 1234567;
const int bb = 123456;
const int cc = 1234;

int main(){
    int n, m;
    while(cin >> n >> m){
        int x = n / 5, y = m / 5;
        int xx = n % 5, yy = m % 5;
        LL ans = (LL)x * (LL)y * 5;
        ans += xx * y + yy * x;
        if(xx + yy >= 5)  ans += (xx + yy) / 5 + (xx + yy) % 5;
        cout << ans << endl;
    }
    return 0;
}

 

posted on 2016-07-09 14:39  dwtfukgv  阅读(205)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3