Codeforces Round #582 C. Book Reading(数学)

C. Book Reading
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Polycarp is reading a book consisting of n
pages numbered from 1 to n. Every time he finishes the page with the number divisible by m, he writes down the last digit of this page number. For example, if n=15 and m=5, pages divisible by m are 5,10,15. Their last digits are 5,0,5 correspondingly, their sum is 10

.

Your task is to calculate the sum of all digits Polycarp has written down.

You have to answer q

independent queries.
Input

The first line of the input contains one integer q
(1≤q≤1000

) — the number of queries.

The following q
lines contain queries, one per line. Each query is given as two integers n and m (1≤n,m≤1016

) — the number of pages in the book and required divisor, respectively.
Output

For each query print the answer for it — the sum of digits written down by Polycarp.
Example
Input
Copy

7
1 1
10 1
100 3
1024 14
998244353 1337
123 144
1234312817382646 13

Output
Copy

1
45
153
294
3359835
0
427262129093995

强烈的直觉让我这么做,可能是上帝让我A了这题,根本没想

#include <iostream>
#include <cstring>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <cstdio>
#include <stdio.h>
#include<queue>
#include<math.h>
using namespace std;
#define ll unsigned long long
int a[150010];
int main()
{  
	int t;
	cin >> t;
	while (t--)
	{
		ll n, m;
		ll ans = 0;
		ll sum = 0;
		scanf("%I64d %I64d", &n, &m);
		for (int i = 1; i <= 10; i++)
		{
			a[i] = m * i % 10;
			sum += a[i];
		}
		ll t = n / (m*10);
		ll t2 = n % (m*10)/m;
		for (int i = 1; i <= t2; i++)
		{
			ans += a[i];
		}
		printf("%I64d\n", t * sum + ans);
	}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Shihao Weng

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值