B. Very Beautiful Number codeference 非常考验数学思维的一个问题

B. Very Beautiful Number
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Teacher thinks that we make a lot of progress. Now we are even allowed to use decimal notation instead of counting sticks. After the test the teacher promised to show us a "very beautiful number". But the problem is, he's left his paper with the number in the teachers' office.

The teacher remembers that the "very beautiful number" was strictly positive, didn't contain any leading zeroes, had the length of exactly p decimal digits, and if we move the last digit of the number to the beginning, it grows exactly x times. Besides, the teacher is sure that among all such numbers the "very beautiful number" is minimal possible.

The teachers' office isn't near and the teacher isn't young. But we've passed the test and we deserved the right to see the "very beautiful number". Help to restore the justice, find the "very beautiful number" for us!

Input

The single line contains integers p, x (1 ≤ p ≤ 106, 1 ≤ x ≤ 9).

Output

If the teacher's made a mistake and such number doesn't exist, then print on a single line "Impossible" (without the quotes). Otherwise, print the "very beautiful number" without leading zeroes.

Sample test(s)
Input
6 5
Output
142857
Input
1 2
Output
Impossible
Input
6 4
Output
102564
Note

Sample 1: 142857·5 = 714285.

Sample 2: The number that consists of a single digit cannot stay what it is when multiplied by 2, thus, the answer to the test sample is "Impossible".



看了这么久才看懂了人家的博客,觉得十分丢人,唉,从这个题目之后的每天都要刷数论题目,好好培养回顾一下我的数学思维,不行啊这样子!!!这个题目是说有p位的n,n*x=一个数,用b【】来存,然后是这个数尾到前面,其余顺眼,那么这个数的最后一位只有可能大于等于x,为啥呢,举例说;

a=142857的7就是b=714285的最前面,最前面那个数是怎么形成的是一个数1*5加上某位得到的,所以可以只必然在x到9之间,而得出了最后一位7的话,那么7*5得到的余数是不是就是我们b的最后一位么!!!!那么a的最前面1是怎么得到的,是1*5+2=7的,而

2是前面给的,1确实本身,只要用7/5就可以得到1了,那么倒数第二位4怎么得到呢???顺次去求即可得到


唉,实在不给力啊!!!!!!!!!!!!!!!

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define N 1000005
int a[N];
int b[N];
int main()
{
    int i,j,k;
    int p,x,flag=0;
    scanf("%d%d",&p,&x);
    int c=0;//jiwei
    for(i=x;i<=9;i++)
    {

        a[p]=i;
        b[1]=i;
        c=0;
        for(j=1;j<=p;j++)
        {
            a[j]=(c*10+b[j])/x;
            c=(c*10+b[j])%x;
            b[j+1]=a[j];
        }

         if(b[p]==(i*x)%10)
        {
            for(int k=1;k<=p;k++)
            printf("%d",a[k]);
            printf("\n");
            flag=1;
            break;
        }
    }
    if(flag==0)
    printf("Impossible\n");
    return 0;
}







  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值