CSU 1392 number Trick (number theory)

Source: Internet
Author: User

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", &AMP;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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.