Home > Back-end >  Algorithm c newbie question, really lost in where
Algorithm c newbie question, really lost in where

Time:10-02

CodePudding user response:

Y calculation is wrong, and the following code compare yourself
While (x<=n) {
Y=y * 10 + a;
S +=y;
X++;
}
Cout CodePudding user response:

With your original code is
While (x<=n) {
S=pow (10 x) * a + y;
M +=s;//change here can also, m constantly accumulating s
Y=s;//y records last calculate s
X++;
}

CodePudding user response:

This problem is not simple, some trouble,
The result, that is, of course, 12345678901234567890132... * a,
But crossing the line is a problem,
Carry is also a problem, but have a 0 as the truncation in the loop, you can block calculation,
N=23, for example, when a=7,

The result is
012345678901234567890123 * 7;
Namely: print again, every time the multiplication of carry will be ended by 0, so just can be segmented to calculate and print,
That is:
7=864197523-0123456789 * 0123456789 * 7=0864197523-0123 * 7=0861
Is three times also print: 864197523 0864197523 0861 (don't) first 0

So a=n=23, 7, 012345678901234567890123 * 7=864197523 0864197523 0861;
0123456789 * {
1=0123456789;
2=0246913578;
3=0370370367? ,
4=0493827156? ,
5=0617283945,
6=0740740734? ,
7=0864197523? ,
8=0987654312? ,
9=1111111101?
}
Build a list of don't have to calculate the mapping relations, only need to compute the last a 0 at the back of the product
  • Related