第一题:完全日期
package fytyfytyu.模拟赛;
public class 完全日期 {
static int mm[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
static int y = 2001, m = 1, d = 1, count = 0;
public static void main(String[] args) {
while (y != 2021 || m != 12 || d != 31) {
// 判断是否闰年
if (y % 400 == 0 || (y % 4 == 0 && y % 100 != 0)) {
mm[2] = 29;
} else {
mm[2] = 28;
}
if (check())
count++;
d++;
if(d>mm[m]) {
d=1;
m++;
}
if(m>12) {
m=1;
y++;
}
}
System.out.println(count);
}
static boolean check() {
int month = mm[m];
int num = y/1000+y/100%10+y/10%10+y%10+m%10+m/10+d%10+d/10;
if (num < 0)
return false;
for (int i = 0; i <= num / 2; i++) {
if (i * i == num) {
System.out.println(num);
return true;
}
}
return false;
}
}
第二题:完美的2
从1 年到2020 看有多少个2;
package fytyfytyu.模拟赛;
public class 美丽的2 {
static int count = 0;
public static void main(String[] args) {
for (int i = 1; i <= 2020; i++) {
String str = i + "";
if (str.contains("2"))
count++;
}
System.out.println(count);
}
}
第三题: 纯质数
package fytyfytyu.模拟赛;
public class 纯质数 {
/*
* 本题总分:10 分
*
* 问题描述
*
* 如果一个正整数只有 1和它本身两个约数,则称为一个质数(又称素数)。 前几个质数是:2,3,5,7,11,13,17,19,23,29,31,37,⋅⋅⋅
* 。 如果一个质数的所有十进制数位都是质数,我们称它为纯质数。例如:2,3,5,7,23,37 都是纯质数,而 11,13,17,19,29,31
* 不是纯质数。当然1,4,35 也不是纯质数。 请问,在 1 到 20210605 中,有多少个纯质数?
*
* 答案提交
*
* 这是一道结果填空的题,你只需要算出结果后提交即可。本题的结果为一个整数,在提交答案时只填写这个整数,填写多余的内容将无法得分。
*/ public static void main(String[] args) {
// TODO Auto-generated method stub
int count = 0 ;
for(long i = 1 ; i <= 20210605;i++) {
if(i>3&&(i%2==0||i%3==0)) continue;
if(i%10==1||i%10 ==0) continue;
if(iszhishu(i)) {
if(i%10==1||i%10 ==0) continue;
if(ischun(i)) {
// System.out.println(i);
count++;
}
}
// if(ischun(i))System.out.println(i);
}
System.out.println(count);
}
//
//判断质数
static boolean iszhishu( long n ) {
for(int i = 2; i<=Math.sqrt(n) ;i++) {
if(n%i==0) return false;
}
return true;
}
//判断是否是纯质数
static boolean ischun(long n ) {
if(n%10==1||n%10 ==0) return false;
while(n!=0 )
{
long m = n%10;
if(m%10==1||m%10==0) return false;
if(!iszhishu(m)) return false;
n/=10;
}
return true;
}
}