Alyona and Numbers
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
Examples
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
Note
Following pairs are suitable in the first sample case:
- for x
- for x = 2 fits y equal to 3 or 8;
- for x = 3 fits y equal to 2, 7 or 12;
- for x = 4 fits y equal to 1, 6 or 11;
- for x = 5 fits y equal to 5 or 10;
- for x = 6 fits y equal to 4 or 9.
Only the pair (1, 4) is suitable in the third sample case.
題意:給兩個數,n,m,這連個數分別從1-n,1-m,從兩個數中取倆個數相加,和是5的倍數;
思路:既然是5的倍數,那,我們每次從n這個數中取數只要只要他%5的餘數就行了,再加上m,(表示最多可以從m中取這麼大的數),再/5就數要求的,從m中取出可以和%5組成5的倍數的個數了,
具體看程式碼就理解,數比較大,要用long long 才能AC,我一開始就卡在這,頭疼。。。。
#include <iostream>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
int main()
{
long long int n,m;
scanf("%lld%lld",&n,&m);
long long int ans=0;
int t;
for(int i=1; i<=n; i++)
{t=i%5;
ans+=(t+m)/5;
}
printf("%lld\n",ans);
return 0;
}
相關推薦
A. Alyona and Numbers(CF ROUND 358 DIV2)
暴力會超時。。。 #include<iostream> using namespace std; int main(){ long long n,m,sum=0; cin>>n>>m; for(int i=1;i<=n;i++){ sum+=(
Alyona and Numbers(數學水題)
題意分析:給定兩個數n,m, 1 <= x <= n, 1 <= y <= m,求一共有多少個有序對(x, y)滿足(x + y) % 5 == 0,題意很簡單,直接上
Alyona and Numbers
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
H - Alyona and Spreadsheet
遞增 title logs example otherwise 個數 quest 數組a sorted H - Alyona and Spreadsheet During the lesson small girl Alyona works with one famous
cf682E Alyona and Triangles
getc str fff ica esc closed com describes cal You are given n points with integer coordinates on the plane. Points are given in a way suc
CF401D 【Roman and Numbers】
ans size ret iostream man esp AS return pan 題意將n(n<=10^18)的各位數字重新排列(不允許有前導零) 求 可以構造幾個mod m等於0的數字解法狀壓f[S][k] 表示選用的位數集合為S,mod m 為k的方案數
B - Alyona and mex
seq res pos ant ++ 說明 ont || title Problem description Alyona‘s mother wants to present an array of n non-negative integers to Alyona. Th
B. Alyona and a tree
++ pre == color span include printf print while 二分+dfs序+前綴和+瞎幾把yy #include "a.h" int n; aLL a; struct edge { int to, nx, w
CF449D Jzzhu and Numbers (狀壓DP+容斥)
進行 狀態 位與 不能 gif using com 答案 {} 題目大意: 給出一個長度為n的序列,構造出一個序列使得它們的位與和為0,求方案數 也就是從序列裏面選出一個非空子集使這些數按位與起來為0. 看了好久才明白題解在幹嘛,我們先要表示出兩兩組合位與和為0的所有情況
CF739B Alyona and a tree 樹上差分
dfs vector con getch get pac += == tro 題目描述 \(Alyona有一棵有 n個節點的樹。這棵樹的根節點是 1。在每個節點裏,Alyona寫了一個正整數,在節點 i 她寫了正整數a_i 。另外,她在這棵樹上的每條邊上寫了一個正整數(不
#DFS序+二分+字首和# Codeforces Round #381 (Div. 1) B. Alyona and a tree
題目連結 B. Alyona and a tree time limit per test 2 seconds memory limit per test 256 megabytes input standard input output&
Codeforces Round #381 (Div. 1) C. Alyona and towers(線段樹)
Alyona has built n towers by putting small cubes some on the top of others. Each cube has size 1 × 1 × 1. A tower is a non-zero amount
Codeforces Round #381 (Div. 1) B. Alyona and a tree dfs序 二分 字首和
B. Alyona and a tree 題目連線: http://codeforces.com/contest/739/problem/B Description Alyona has a tree with n vertices. The root of the
Mashmokh and Numbers CodeForces - 415C
題意:就是n個數和k,每次按順序那兩個數,最大公約數的和為k。 思路:注意:當n=1,k>0時一定不存在,還有n=1,k=0時為1即可。 然後再正常情況下,第一組的最大公約數為k-n/2+1即可,後面是含有素數。(本來,配的是素數和素數+1, 然後會怕第一組會重複,後來直解兩個素數了,因為第一
codeforces 358D. Alyona and Strings (dp)
D. Alyona and Strings time limit per test 2 seconds memory limit per test 256 megaby
codeforces #235 D. Roman and Numbers 題解
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve a
cf 777c Alyona and Spreadsheet(記憶化搜尋+遞推)
這題題目說了(1 ≤ n·m ≤ 100 000),那麼n和m就不可能同時取到最大1e5,而且鄰接矩陣也開不了1e5*1e5這麼大,因此不能提前開mp陣列,要在輸入了n和m之後,根據具體的n和m來開mp陣列。 h[i]記錄的是第i行最多能到第幾行,l[j]表示第j列
Codeforces Round #114 (Div. 1) C Wizards and Numbers
swa ble style out 數字 pac 如果 div for 題目鏈接:Wizards and Numbers 題意:有兩個數字a, b,假設 a>b,兩個玩家進行遊戲,有兩種操作:1. 令 a=a-b^k,k為正數,且需要保證操作後 a 仍然非負;2. 令
cf449D. Jzzhu and Numbers(容斥原理 高維字首和)
題意 題目連結 給出\(n\)個數,問任意選幾個數,它們\(\&\)起來等於\(0\)的方案數 Sol 正解居然是容斥原理Orz,然而本蒟蒻完全想不到。。 考慮每一種方案 答案=任意一種方案 - 至少有\(1\)位為\(1\)的方案 + 至少有兩位為\(1\)的方案 - 至少有三位為\(1\)的方案
codeforces 449 D Jzzhu and Numbers(容斥+dp)
這題真的爆炸難懂...待補。 程式碼: #include <bits/stdc++.h> using namespace std; const int mod=1e9+7; const