Codeforces Round #358 (Div. 2) A. Alyona and Numbers

本文提供了一种解决 Codeforces Round #358 (Div.2) A. Alyona and Numbers 问题的方法。该问题要求在 x 属于 [1, n] 和 y 属于 [1, m] 的条件下找到所有使得 (x + y) % 5 == 0 的数对 (x, y) 的数量。通过分析 5 的倍数和非 5 倍数的情况,使用 C++ 实现了一个高效的解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Codeforces Round #358 (Div. 2) A. Alyona and Numbers

题意:找在x属于[1,n]、y属于[1,m]找出(x+y)%5==0的个数,n和m范围都是10^6,只能一重循环,不然TLE,结果cnt一定是longlong不然爆掉的;考虑两种情况,5的倍数和非5的倍数,只有非5的倍数要考虑最后一种情况。

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <ctime>
#include <set>
#include <map>
#include <cmath>
using namespace std;
typedef long long LL;
int main(){
    int n,m,j;
    while(~scanf("%d %d",&n,&m)){
        LL cnt = 0;
        for(int i=1;i<=n;i++){
            if(i%5==0) { //5的倍数
                cnt+= m/5;
                continue;   
            }
            cnt += (m/5); //非5的倍数 
            for(int j=m%5;j>=1;j--){ //最后一位
                if((i+j)%5==0){
                    cnt++;
                }
            }
        //cout<<i<<" "<<cnt<<endl;
        }
        printf("%lld\n",cnt);
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值