A jamcoin is a string of N ¡Ý 2 digits with the following properties:
Every digit is either 0 or 1.
The first digit is 1 and the last digit is 1.
If you interpret the string in any base between 2 and 10, inclusive, the resulting number is not prime.
Not every string of 0s and 1s is a jamcoin. For example, 101 is not a jamcoin; its interpretation
in base 2 is 5, which is prime. But the string 1001 is a jamcoin: in bases 2 through 10,
its interpretation is 9, 28, 65, 126, 217, 344, 513, 730, and 1001, respectively,
and none of those is prime.
We hear that there may be communities that use jamcoins as a form of currency. When sending someone
a jamcoin, it is polite to prove that the jamcoin is legitimate by including a nontrivial divisor
of that jamcoin's interpretation in each base from 2 to 10. (A nontrivial divisor for
a positive integer K is some positive integer other than 1 or K that evenly divides K.)
For convenience, these divisors must be expressed in base 10.
For example, for the jamcoin 1001 mentioned above, a possible set of nontrivial divisors for the
base 2 through 10 interpretations of the jamcoin would be: 3, 7, 5, 6, 31, 8, 27, 5, and 77, respectively.
Can you produce J different jamcoins of length N, along with proof that they are legitimate?
中文;
jamcoin是N¡Y 2位数字组成的字符串有以下属性:
每一个数字是0或1。
第一个数字是1,最后一个数字是1。
如果你解释2和10之间进制的字符串在任何基础,包容,结果数不是素数。
不是每一串0和1是jamcoin。例如,101年不是一个jamcoin;其解释
在二进制时是5,这是质数。但是字符串1001是一个jamcoin:在二进制到十进制,
其解释分别是9,28,65,126,217,344,513,730和1001
,这些都不是是质数。
我们听说有社区使用jamcoins作为货币的一种形式。当发送一个人
jamcoin,礼貌的证明jamcoin是合法的,包括重要的因子
jamcoin的解释在每个二进制到十进制(一个重要的因子
一个正整数K比1或其他正整数K均分K)
为了方便起见,这些因数必须以10为底的表达。
例如,1001年jamcoin上面提到的,一组可能的重要的因数在二进制到十进制 jamcoin将那些数分别可以除:3、7、5、6、31、8、27、5和77,
你能生产不同长度的jamcoins J N,连同证明他们是合法的吗?
package jamcoin;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
int n=in.nextInt();
int[] a=new int[n];
a[0]=1;a[n-1]=1;
dfs(a,n,1);
}
public static void dfs(int a[],int n,int count){ //遍历并判断
if((n-1)==count){ //当数组全部排序完成
for(int i=2;i<=10;i++){ //判断每个进制不是质数
if(zhishu(pow1(a,n,i))==1){ //判断
if(i==10){ //判断到最后一个也符合要求是jamcoin
//System.out.print("yes ");
for(int y=0;y<n;y++)
System.out.print(a[y]); //输出jiacoin
System.out.println();
}
else
continue;
}
else
return ;
}
}
if(count>(n-2))return ;
a[count]=1;
dfs(a,n,count+1);
a[count]=0;
dfs(a,n,count+1);
}
public static int zhishu(long l){ //判断质数
if(l<=1) return 1;
for(int i=2;i<l;i++)
if(l%i==0)
return 1;
return 0;
}
public static long pow1(int a[],int n,int jinzhi){ //求进制下的值
long all=0;
for(int i=0;i<n;i++){
if(a[i]==1)
all=(long) (all+Math.pow(jinzhi,i));
else
continue;
}
return all;
}
}