C. Book Reading(周期规律+等差数列)

在这里插入图片描述
这道题就是求[1,n]内,能被m整除的数的个位数的和为多少;题意很简单吧,嘻嘻;但是一看1e16;枚举早爆了;
所以我猜了一下应该是什么规律;
后面我发现这个问题如果一个数x能被m整除;那么x的值可以为m,2m,3m,4m,…;
我发现是等差数列;也就是x=num*m(num>=1的整数);
然后我写了一下样例;发现这个问题:
在这里插入图片描述
我把个位数保留下来;可以发现这个东西是以10为周期的;之后我又写了1337,和14。。。。发现都是以10为周期;而且有数论知识我可以知道[1,n]内能被m整除的个数就是n/m个;那么我就可以先把10个求出来,然后再来看n/m的个数问题了;所以这个题就AC了;
AC代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll T,n,m;
ll save[20];
int main(){
   scanf("%lld",&T);
   while(T--){
   	 scanf("%lld %lld",&n,&m);
   	 if(m>n){///如果m>n了那么没有数,就是0了
   	 	puts("0");
	  }else{
	  	ll num=n/m,t1=0,t2=0;
	     for(int i=1;i<=10;i++){
	     	 save[i]=(m*i)%10;//用save来保存10个尾数
	     	 t1+=(m*i)%10;//记录一个周期的和
		 }
		 for(int i=1;i<=num%10;i++){///记录多余的数的和
		 	t2+=(m*i)%10;
		 }
		printf("%lld\n",t1*(num/10)+t2);//(num/10)表示有多少个周期,然后t2是多余的数;
	  }
   }
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据提供的引用内容,以下是一个关于阅读能力重要性及如何发展阅读能力的简短文章: The Importance of Reading Ability and How to Develop It Reading ability plays a crucial role in our personal and academic development. It not only enhances our knowledge and understanding of the world but also improves our critical thinking and communication skills. Therefore, it is essential to develop and nurture this skill. To develop reading ability, one should start by cultivating a reading habit. Allocating a specific time each day for reading can help establish a routine and make it a regular practice. Additionally, choosing a variety of reading materials, such as books, newspapers, and online articles, can expose us to different writing styles and perspectives. Furthermore, active reading techniques can enhance comprehension and retention. This includes previewing the text, highlighting key points, and summarizing the main ideas. Taking notes while reading can also aid in understanding and remembering the content. Moreover, joining book clubs or discussion groups can provide opportunities for sharing insights and engaging in meaningful conversations about the reading material. This can further deepen our understanding and broaden our perspectives. In conclusion, developing reading ability is crucial for personal growth and academic success. By cultivating a reading habit, employing active reading techniques, and engaging in discussions, we can enhance our reading skills and reap the benefits of a well-developed reading ability.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值