CodeForces 682A Alyona and Numbers (水题)
Alyona and Numbers
题目链接:
http://acm.hust.edu.cn/vjudge/contest/121333#problem/A
Description
After finishing eating her bun, Alyona came up with two integers n and m. She decided to write down two columns of integers — the first column containing integers from 1 to n and the second containing integers from 1 to m. Now the girl wants to count how many pairs of integers she can choose, one from the first column and the other from the second column, such that their sum is divisible by 5.
Formally, Alyona wants to count the number of pairs of integers (x, y) such that 1 ≤ x ≤ n, 1 ≤ y ≤ m and equals 0.
As usual, Alyona has some troubles and asks you to help.
Input
The only line of the input contains two integers n and m (1 ≤ n, m ≤ 1 000 000).
Output
Print the only integer — the number of pairs of integers (x, y) such that 1 ≤ x ≤ n, 1 ≤ y ≤ m and (x + y) is divisible by 5.
Sample Input
Input
6 12
Output
14
Input
11 14
Output
31
Input
1 5
Output
1
Input
3 8
Output
5
Input
5 7
Output
7
Input
21 21
Output
88
题意:
找出有多少数对(x, y), 1 ≤ x ≤ n, 1 ≤ y ≤ m 使得x+y能整除5;
题解:
直接模拟找出所有数模5的同余数;
注意long long;
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#define LL long long
#define eps 1e-8
#define maxn 110
#define inf 0x3f3f3f3f
#define IN freopen("in.txt","r",stdin);
using namespace std;
int n,m;
LL a[6],b[6];
int main(int argc, char const *argv[])
{
//IN;
while(scanf("%d %d",&n,&m) != EOF) {
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
for(int i=1; i<=n; i++){
a[i%5]++;
}
for(int i=1; i<=m; i++){
b[i%5]++;
}
LL ans = a[0] * b[0];
for(int i=1; i<5; i++) {
ans += a[i]*b[5-i];
}
printf("%I64d\n", ans);
}
return 0;
}
CodeForces 682A Alyona and Numbers (水题)的更多相关文章
- CodeForces 682A Alyona and Numbers (水题,数学)
题意:给定两个数 m,n,问你在从1到 n,和从 1到 m中任选两个数加起来是5的倍数,问你有多少个. 析:先计算 m 和 n中有多少个取模5是从0到4的,然后根据排列组合,相乘就得到了小于等于 m ...
- Codeforces Round #358 (Div. 2) A. Alyona and Numbers 水题
A. Alyona and Numbers 题目连接: http://www.codeforces.com/contest/682/problem/A Description After finish ...
- VK Cup 2016 - Qualification Round 2 A. Home Numbers 水题
A. Home Numbers 题目连接: http://www.codeforces.com/contest/638/problem/A Description The main street of ...
- codeforces 577B B. Modulo Sum(水题)
题目链接: B. Modulo Sum time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Gym 100286G Giant Screen 水题
Problem G.Giant ScreenTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/con ...
- codeforces 659A A. Round House(水题)
题目链接: A. Round House time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #367 (Div. 2)---水题 | dp | 01字典树
A.Beru-taxi 水题:有一个人站在(sx,sy)的位置,有n辆出租车,正向这个人匀速赶来,每个出租车的位置是(xi, yi) 速度是 Vi;求人最少需要等的时间: 单间循环即可: #inclu ...
- codeforces 696A Lorenzo Von Matterhorn 水题
这题一眼看就是水题,map随便计 然后我之所以发这个题解,是因为我用了log2()这个函数判断在哪一层 我只能说我真是太傻逼了,这个函数以前听人说有精度问题,还慢,为了图快用的,没想到被坑惨了,以后尽 ...
- CodeForces 589I Lottery (暴力,水题)
题意:给定 n 和 k,然后是 n 个数,表示1-k的一个值,问你修改最少的数,使得所有的1-k的数目都等于n/k. 析:水题,只要用每个数减去n/k,然后取模,加起来除以2,就ok了. 代码如下: ...
随机推荐
- ubuntu下android源码下载
步骤一: 首先保证你的ubuntu系统电脑可以顺利游览google,我们是将etc下 hosts替换掉,推荐hosts: http://laod.cn/hosts/2015-google...host ...
- SQLserver临时表
IF EXISTS (SELECT * FROM SYSOBJECTS WHERE NAME='#temp') DROP TABLE #tempGOSELECT ID,XM,ADDDW INTO #t ...
- IOS代码
//// MJViewController.m// UITableView-编辑模式//// Created by mj on 13-4-11.// Copyright (c) 2013年 itcas ...
- TUXEDO错误解决方案
错误1: root@tfjus:/opt/tuxedo/simpapp# buildclient -f simpcl.c -o simpcl simpcl.c: In function 'main': ...
- 学习Hadoop的资料
1)Cygwin相关资料 (1)Cygwin上安装.启动ssh服务失败.ssh localhost失败的解决方案 地址:http://blog.163.com/pwcrab/blog/static/1 ...
- bzoj1297: [SCOI2009]迷路
矩阵. 一个图的邻接矩阵的m次幂相当于 长度恰好为m的路径数.这要求边权为1. 因为边权小于等于9,所以可以把一个点拆成9的点. 拆成的第(i+1)个点向第i个点连边. 如果存在边(u,v,w) 就由 ...
- Spring 使用注解方式进行事务管理
转载:http://www.cnblogs.com/younggun/archive/2013/07/16/3193800.html 使用步骤: 步骤一.在spring配置文件中引入<tx:&g ...
- vs2010 js代码折叠
方法一:插件 在Visaul Studio 2010中写js或css代码,缺少像写C#代码时的那种折叠功能,当代码比较多时,就很不方便. 但是已经有VS2010扩展支持这个功能,它就是--JSEn ...
- MySQL基础之第9章 触发器
触发器(TRIGGER)是由事件来触发某个操作.这些事件包括INSERT语句.UPDATE语句和DELETE语句.当数据库系统执行这些事件时,就会激活触发器执行相应的操作.MySQL从5.0.2版本开 ...
- Windows 编译器选项 Runtime Library
https://msdn.microsoft.com/library/2kzt1wy3%28v=vs.100%29.aspx http://blog.csdn.net/ybxuwei/article/ ...