View Code of Problem 3920

#include<stdio.h>
#include<math.h>
#include<string.h>
//#include<algorithm>
#include <bits/stdc++.h>

using namespace std;

int main() {
	int T;
	long long int m,n;
	int i;
	scanf("%d",&T);
	while(T--) {
		long long int sum=0;
		scanf("%lld %lld",&n,&m);
		long long int tempsum=0;
		for(i=1; i<=10; i++) {
			tempsum=tempsum+(m*i)%10;
		}
		if(m==n) {
			cout<<m%10<<endl;
		} else {
			long long int t=n/(m*10);
			sum=sum+tempsum*t;

			for(long long i=t*10*m+m; i<=n; i+=m) sum+=i%10;
			cout<<sum<<endl;
//			int z=n%(m*10);
//			int tempz=0;
//			while(tempz<=z) {
//				sum=sum+tempz%10;
//				tempz=tempz+m;
//			}
//			printf("%lld\n",sum);
		}
	}
}

Double click to view unformatted code.


Back to problem 3920