23蓝桥小题

189 阅读1分钟

填空题其一

//问题描述:令S=1!+2!+3!······+202320232023!
//求S的末尾9位数字(提示:答案首位不为0)

import java.util.Scanner;

public class java_lan_qiao_01 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        long mod = (long) 1e9;
        long sum = 0,res=1;
        for (int i = 1; i <=300; i++) {
            res=res*i%mod;
            sum+=res;
            sum%=mod;
            System.out.println(sum);
        }
        System.out.println(sum);
    }
}

编程题其一

//哈沙德数:在某个固定进位制中,可以被各个数字之和整除的正整数。(126)10 mod(1+2+6)=0;
// (126)10 = (176)8  mod  (1+7+6)=0
//(126)10  =  (7e)16   mod  (7+e) =0
//在四个进位制全部为哈沙德数的为幸运数字
//1-10个幸运数字为1,2,4,6,8,40,48,72,120,126
//请问第2023个幸运数字是(十进制表示)?

import java.util.Scanner;




public class lan_qiao_02 {
    public static void main(String[] args) {
        Scanner scan =new Scanner(System.in);
        int res =0,n=1;
        while (res<2023){
            if (is(n,2)&&is(n,8)&&is(n,16)&&is(n,10))
                res++;
            if(res==2023)
                System.out.println(n);
            n++;
        }
    }
    public static boolean is(int n,int x){//n表示十进制位数的值,x表示进制位
        int res = 0,ans = n;
        while(ans>0){
            res+=ans%x;
            ans/=x;
        }
        return n % res==0;
    }
}
    
//进制转化API:String str =Integer.toString(x,y);
//x为十进制数,y为转化后数

水文感言:真不是我想水,是我最近报了蓝桥杯,三百块啊三百块,呜呜呜,实在不想让这三百块打水漂了......所以最近的文都是算法小题。进度也落下了不少......年后这个学期我必加倍努力,尽量确保学习和算法不耽误!!!