Count a a a ⋯ a a a n a _ ×b aaa ⋯ aaa⏟n how many numbers d are in the results of a × b, a, b, d are all single digits.
Example explanation:
3333333333*3=9999999999, there are 10 9s in it.
Input multiple sets of test data.
The first line has an integer T, which represents the number of test data. (1≤T≤5000)
Next there are T lines, each line represents a set of test data, there are 4 integers a, b, d, n. (1≤a, b≤9, 0≤d≤9, 1≤n≤10^9) Output For each set of data, output an integer on one line to represent the answer. Sample Input
2 3 3 9 10 3 3 0 10
Sample Output
10 0
Analog Multiplication
#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; intmain() { int t; int a,b,d,n; scanf("%d",&t); while(t--) { scanf("%d%d%d%d",&a,&b,&d,&n); int rest=0,next=0; int res=-1; int years; int sum=0; for(int i=0; i<n; i++) { ans=a*b+next; next=ans/10; rest=ans%10; if(ans==res) { if(rest==d) sum+=n-i; break; } res=ans; if(rest==d) sum++; } if(next!=0&&next==d) sum++; printf("%d\n",sum); } }