首页 > 其他分享 >Investigating Div-Sum Property UVA - 11361

Investigating Div-Sum Property UVA - 11361

时间:2023-04-19 16:55:07浏览次数:42  
标签:tes int Sum 11361 Investigating UVA include

 

定问在[A,B] 中,有多少个整数本身能被m整除,各个数位上数字之和也能被m整除?

 

 

#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
vector<int> a;
 int m,f[40][105][105][2];
 
 int dfs(int x,int v1,int v2,int flg){
 	if(x<0)
 		return (v1==0&&v2==0);
 	if(f[x][v1][v2][flg]!=-1) return f[x][v1][v2][flg]; 
 	
 	int end= (flg?a[x]:9);
 	int t=0;
 	for(int i=0;i<=end;i++){
 		t+=dfs(x-1,(v1+i)%m,(v2*10+i)%m,flg&&(i==end));
 	}
 	if(flg==0) f[x][v1][v2][flg]=t;
 	return t;
 }
 int sov(int x){
 	a.clear();
 	memset(f,-1,sizeof f);
 	while(x){
 		a.push_back(x%10);
 		x/=10 ;
 	}
 	return dfs(a.size()-1,0,0,1);
 }
 signed main(){
 	int tes; cin>>tes;
 	while(tes--){
 		int x,y;
 		cin>>x>>y>>m;
 		if(m>=100){ cout<<0<<endl;continue;}
 	
 		cout<< sov(y)-sov(x-1) <<endl;
 	}
 }
 
 
 

 

标签:tes,int,Sum,11361,Investigating,UVA,include
From: https://www.cnblogs.com/towboa/p/17333872.html

相关文章

  • hdoj The sum problem 2058 (数学等差公式&技巧转换)
    ThesumproblemTimeLimit:5000/1000MS(Java/Others)    MemoryLimit:32768/32768K(Java/Others)TotalSubmission(s):21416    AcceptedSubmission(s):6287ProblemDescriptionGivenasequence1,2,3,......N,yourjob......
  • CodeForces - 616E Sum of Remainders (数论)大数取余求和 好题
    CodeForces-616ESumofRemaindersTimeLimit: 2000MS MemoryLimit: 262144KB 64bitIOFormat: %I64d&%I64uSubmit StatusDescriptionCalculatethevalueofthesum: nmod1 + nmod2 + nmod3 +...+ nmodm.Astheresultcanbeve......
  • UVA11806 Cheerleaders
    你有一个n×m的网格图,现在你要将K个人放在网格中,满足一下条件:网格图的四个边都至少有一个人。每个格子上不能有两个人。每个人必须都有位置。注意:四个角的人可以同时算作在两个边上  容斥原理   J=0时就是allAnswer#include<iostream>#include<cstri......
  • Hackers' Crackdown UVA11825
    你需要将n个集合分成尽量多组,使得每一组里面所有集合的并集等于全集  32122022014111013120   f[S]=max(f[S],f[S-j]+1)且j是一个包含所有点的集合#include<iostream>#include<algorithm>#include<cstring>usingname......
  • Robotruck UVA - 1169
    有n个垃圾,第i个垃圾的坐标为(xi,yi),重量为wi。有一个机器人,要按照编号从小到大的顺序捡起所有垃圾并扔进垃圾桶(垃圾桶在原点(0,0))。机器人可以捡起几个垃圾以后一起扔掉,但任何时候其手中的垃圾总重量不能超过最大载重C。两点间的行走距离为曼哈顿距离(即横坐标之差的绝对值加上纵......
  • Add Again UVA - 11076
     defineS,itissumofallpossiblepermutationsofagivensetofdigits.Forexample,ifthedigitsare<123>,thensixpossiblepermutationsare<123>,<132>,<213>,<231>,<312>,<321>andthesumofthemis......
  • The Super Powers UVA - 11752
     求1~2^64区间里,有多少合法数X合法数:X=a^b,至少存在2个不同的a #include<iostream>#include<algorithm>#include<vector>usingnamespacestd;constintN=65536+3;intb[int(1e6)];__int128_tMAX=1;voidinit(){ inti,j; b[0]=b[1]=1; fo......
  • LCM Cardinality UVA - 10892
    给出n,求有多少对(a,b)(a<b),满足LCM(a,b)=n 暴力求所有因数#include<iostream>#include<algorithm>#include<vector>usingnamespacestd;constintN=1e4+20;#defineintlonglongconstintinf=1e9;voidsov(intn){ vector<int>v;......
  • Again Prime? No Time. UVA - 10780
    给定m,n,求最大的k使得m^k∣n! 分解质因数   #include<iostream>#include<cstring>#include<sstream>usingnamespacestd;constintN=1e4+20;constintinf=1e9;intn,m,a[N],b[N];intprime[N],tot,vis[N];voidinit(inttop){ for(......
  • Uva--679 Dropping Balls(二叉树的编号)
    记录23:282023-4-16https://onlinejudge.org/external/6/679.pdfreference:《算法竞赛入门经典第二版》例题6-6二叉树,这里是完全二叉树,使用模拟的方式应该会TLE(虽然我用模拟的方式也TLE了,但不是这个原因,下面会提到原因)不用模拟的方式,转换思路,使用递归的方式去思考。这里......