C. Book Reading 求在[1,n]中的数中,能整除m的数 的个位的和
C. Book Reading
1 second
256 megabytes
standard input
standard output
Polycarp is reading a book consisting of nn pages numbered from 11 to nn. Every time he finishes the page with the number divisible by mm, he writes down the last digit of this page number. For example, if n=15n=15 and m=5m=5, pages divisible by mm are 5,10,155,10,15. Their last digits are 5,0,55,0,5 correspondingly, their sum is 1010.
Your task is to calculate the sum of all digits Polycarp has written down.
You have to answer qq independent queries.
The first line of the input contains one integer qq (1≤q≤10001≤q≤1000) — the number of queries.
The following qq lines contain queries, one per line. Each query is given as two integers nn and mm (1≤n,m≤10161≤n,m≤1016) — the number of pages in the book and required divisor, respectively.
For each query print the answer for it — the sum of digits written down by Polycarp.
7
1 1
10 1
100 3
1024 14
998244353 1337
123 144
1234312817382646 13
1
45
153
294
3359835
0
427262129093995 题意:输入n,m; 求在[1,n]中的数中,能整除m的数 的个位的和 题解:规律+模拟 例如:n=100 m=3 1-n能被3整除的有:3 6 9 12 15 18 21 24 27 30 33 36 ……99 余数分别为: 3 6 9 2 5 8 1 4 7 0 3 6 …… 9 发现循环节的个数有:10个数 且和为3 + 6+9+2+5+8+1+4+7+0 = 45 所以最后的结果为:(n/m/循环节的个数) * 一个循环的和 + 不够一个循环节的和
#include<iostream>
#include<string.h>
#include<string>
#include<algorithm>
#include<queue>
#define ll long long
using namespace std;
int vis[][]={ //vis[i][0] 指m的个位数为i的时候循环节长度为vis[i][0],vis[i][j] (j>=1)是循环内的每一个数
{,},
{,,,,,,,,,,},
{,,,,,},
{,,,,,,,,,,},
{,,,,,},
{,,},
{,,,,,},
{,,,,,,,,,,},
{,,,,,},
{,,,,,,,,,,}
};
int sum[];
int main()
{
ll t, n, m, ans;
cin >> t;
for(int i=;i<;i++)
{
for(int j=;j<;j++)
sum[i]=sum[i]+vis[i][j];
} while (t--)
{
ans = ;
cin >> n >> m;
ll k=n/m;
ll x=m%;
ans=ans+sum[x]*(k/vis[x][]);
k=k%vis[x][];
for(int i=;i<=k;i++)//不够一个循环的和
ans=ans+vis[x][i];
cout<<ans<<endl;
}
return ;
}
C. Book Reading 求在[1,n]中的数中,能整除m的数 的个位的和的更多相关文章
- js如何求一组数中的极值
这是一个很简单的问题,现在我们从循环开始,例如一组数[5,2,1,3,4];求其中的最大值,那么首先我们要定义一个max的中间变量,遍历数组,当遇到比max值大则赋值给max,直到循环结束,就能获取这 ...
- 【C语言】输入一组整数,求出这组数字子序列和中最大值
//输入一组整数.求出这组数字子序列和中最大值 #include <stdio.h> int MAxSum(int arr[],int len) { int maxsum = 0; int ...
- Jsの数组练习-求一组数中的最大值和最小值,以及所在位置
要求:求一组数中的最大值和最小值,以及所在位置 代码实现: <!DOCTYPE html> <html lang="en"> <head> &l ...
- hdu3065 病毒侵袭持续中 AC自动机入门题 N(N <= 1000)个长度不大于50的模式串(保证所有的模式串都不相同), 一个长度不大于2000000的待匹配串,求模式串在待匹配串中的出现次数。
/** 题目:hdu3065 病毒侵袭持续中 链接:http://acm.hdu.edu.cn/showproblem.php?pid=3065 题意:N(N <= 1000)个长度不大于50的 ...
- 算法题:给你一个自然数N,求[6, N]之内的全部素数中, 两两之和为偶数的那些偶数。
/* 算法题:给你一个自然数N,求[6, N]之内的全部素数中. 两两之和为偶数的那些偶数. */ #include <iostream> using namespace std; voi ...
- Frogger POJ - 2253(求两个石头之间”所有通路中最长边中“的最小边)
题意 题目主要说的是,有两只青蛙,在两个石头上,他们之间也有一些石头,一只青蛙要想到达另一只青蛙所在地方,必须跳在石头上.题目中给出了两只青蛙的初始位置,以及剩余石头的位置,问一只青蛙到达另一只青 ...
- lua中 table 元表中元方法的重构实现
转载请标明出处http://www.cnblogs.com/zblade/ lua作为游戏的热更新首选的脚本,其优势不再过多的赘述.今天,我主要写一下如何重写lua中的元方法,通过自己的重写来实现对l ...
- 欧拉函数(小于或等于n的数中与n互质的数的数目)&& 欧拉函数线性筛法
[欧拉函数] 在数论,对正整数n,欧拉函数是少于或等于n的数中与n互质的数的数目.此函数以其首名研究者欧拉命名,它又称为Euler’s totient function.φ函数.欧拉商数等. 例如φ( ...
- 给定两个数组,这两个数组是排序好的,让你求这两个数组合到一起之后第K大的数。
题目:给定两个数组,这两个数组是排序好的,让你求这两个数组合到一起之后第K大的数. 解题思路: 首先取得数组a的中位数a[aMid],然后在b中二分查找a[aMid],得到b[bMid],b[bSt] ...
随机推荐
- TakeColor下载及调节鼠标指针不一致的问题
取色器下载链接: 链接:https://pan.baidu.com/s/19TBWZA2ltaLQjzskTipnmg 提取码:2uz3 若出现指针与鼠标不一致: TakeColor v8.0 > ...
- Spring Boot中Restful Api的异常统一处理
我们在用Spring Boot去向前端提供Restful Api接口时,经常会遇到接口处理异常的情况,产生异常的可能原因是参数错误,空指针异常,SQL执行错误等等. 当发生这些异常时,Spring B ...
- [题解] 2019牛客暑期多校第三场H题 Magic Line
题目链接:https://ac.nowcoder.com/acm/contest/883/H 题意:二维平面上有n个不同的点,构造一条直线把平面分成两个点数相同的部分. 题解:对这n个点以x为第一关键 ...
- 解决IE8不兼容 background-size
IE8下,使用background-size适应盒子大小时不兼容,效果如下图: 网上找资料,说添加如下代码可以兼容IE8 filter: progid:DXImageTransform.Microso ...
- vagrant up 报VirtualBox错误
Debug output $ $ vagrant.exe up ==> default: Checking if box 'janihur/ubuntu-1404-desktop' is up ...
- JavaScript的技巧45招
JavaScript奇技淫巧45招 来自仲老师的分享: 原文地址[http://chensd.com/2015-01/45-useful-javascript-tips-tricks-and-best ...
- 一个arctan积分的两种解法
\[\Large\int_{0}^{1}\frac{\arctan x}{\sqrt{1-x^{2}}}\mathrm{d}x\] \(\Large\mathbf{Solution:}\) 首先第一种 ...
- 吴裕雄 python 神经网络——TensorFlow 图像预处理完整样例
import numpy as np import tensorflow as tf import matplotlib.pyplot as plt def distort_color(image, ...
- 误删/boot下文件或目录的修复方式!
步骤:进入硬盘的急救模式,进入磁盘,挂载光盘到/media上,rpm安装内核到media目录下,从装grub程序到/dev/sda,然后将grub文件从定向到/boot下,然后重启. 第一步:进入bi ...
- python学习 —— post请求方法的应用
声明:本篇仅基于兴趣以及技术研究而对B站曾经发生过的抢楼事件背后相关技术原理进行研究而写.请不要将其作为私利而对B站以及B站用户体验造成影响!谢谢合作!若本文对B站及其用户带来困扰,请联系本人删除本文 ...