看了这么久才看懂了人家的博客,觉得十分丢人,唉,从这个题目之后的每天都要刷数论题目,好好培养回顾一下我的数学思维,不行啊这样子!!!这个题目是说有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;
}