Test instructions: Enter a number x from small to large output all satisfied (k*leny+y) *x=y*10+k k*leny+y
Idea: Because X is a floating-point number, both sides of the equation are multiplied by 1e4.
Converts the equation to K (leny*x-1) *1e4=y (1E5-X*1E4)
It is possible to enumerate Len K to find out if there are any time and conditions for the presence of Y
It's a little bit more than a pit, but it's okay to ask Kay or die.
The first conversion of X should pay attention to the floating point error x= (int) (lx*10000+0.5);
Second, because the two sides of the equation may be 0 to find the Y is also 0 that is the number of single-digit
So we have a special sentence for this situation.
printf ("%d", k);
if (y>0) printf ("%d", y);
printf ("\ n");
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm>using namespace STD; #define LL long longint len (int n) {int res=1; for (int i=1;i<n;i++) {res*=10; } return res; int digit (long long num) {int cnt=0; while (num) {num/=10; cnt++; } return CNT;} int main () {Long long leny,y; int k; Double LX; int i,j; while (scanf ("%lf", &LX)!=eof) {int ok=0; ll x= (int) (lx*10000+0.5); if (lx>=10) {printf ("No solution\n"); Continue } ll Leny=1; for (i=0;i<=7;i++) {for (k=1;k<=9;k++) {long temp= (long Long) k* (lo ng long) (leny*x) -1e4); Long Long temp1=1e5-x; if (temp%temp1!=0) continue; Y=TEMP/TEMP1; if (digit (y) ==i) {if (ok==0) ok=1; printf ("%d", k); if (y>0) printf ("%d", y); printf ("\ n"); }} leny*=10; } if (ok==0) printf ("No solution\n"); } return 0;}
CSU 1392 number Trick (number theory)