1 条题解

  • 0
    @ 2023-6-11 12:24:21

    C++ :

    #include <bits/stdc++.h>
    using namespace std;
    
    bool sushu(int n){
    	for(int i = 2;i <= sqrt(n);i++){
    		if(n % i == 0) return false;
    	}
    	
    	if(n == 1) return false;
    	return true;
    }
    
    int main(){
    	for(int i = 1;i <= 200;i++){
    		if(sushu(i)){
    			if(i >= 65 && i <= 65 + 25 || i >= 97 && i <= 122){
    				cout<<i<<" "<<(char)i<<endl;
    			}
    		}
    	}
    }
    
    
    

    Java :

    
    import java.util.Scanner;
    public class Main {
        public static void main(String[] args) {
            Scanner scanner = new Scanner(System.in);
    //        String c = scanner.next();
    //        int num1 = scanner.nextInt();
            for(int i = 65;i <= 90;i++){
                if(isPrime(i)){
                    System.out.println(i + " " + (char)(i));
                }
            }for(int i = 97;i <= 122;i++){
                if(isPrime(i)){
                    System.out.println(i + " " + (char)(i));
                }
            }
    
    
        }public static void paiXu(int[] a,int length){
            int temp;
            for(int i = 0;i < length - 1;i++){
                for(int k = 0;k < length - i - 1;k++){
                    if(a[k] > a[k + 1]){
                        temp = a[k];
                        a[k] = a[k + 1];
                        a[k + 1] = temp;
                    }
                }
            }
        }
        public static int er(int n)
        {
            if(n==0)
            {return 0;}
            int f1=1,f2;
            n--;
            while(n != 0)
            {
                f2=f1*2;
                f1=f2;
                n--;
            }
            return f1;
        }
    
        public static void paiXud(int[] a){
            int temp;
            for(int i = 0;i < a.length - 1;i++){
                for(int k = 0;k < a.length - i - 1;k++){
                    if(a[k] < a[k + 1]){
                        temp = a[k];
                        a[k] = a[k + 1];
                        a[k + 1] = temp;
                    }
                }
            }
        } public static void paiXux(int[] a){
            int temp;
            for(int i = 0;i < a.length - 1;i++){
                for(int k = 0;k < a.length - i - 1;k++){
                    if(a[k] > a[k + 1]){
                        temp = a[k];
                        a[k] = a[k + 1];
                        a[k + 1] = temp;
                    }
                }
            }
        }
    
        public static int MAX2(int[][] a){
            int max = a[0][0];
            for (int i = 0; i < a.length; i++) {
                for(int j = 0;j < a[0].length;j++){
                    if(max < a[i][j])max = a[i][j];
                }
            }
            return max;
        }public static int MIN2(int[][] a){
            int min = a[0][0];
            for (int i = 0; i < a.length; i++) {
                for(int j = 0;j < a[0].length;j++){
                    if(min > a[i][j])min = a[i][j];
                }
            }
            return min;
        }
        public static int MAX(int[] a){
            int max = a[0];
            for (int i = 0; i < a.length; i++) {
                if(max < a[i]){
                    max = a[i];
                }
            }
            return max;
        }
    
        public static int MIN(int[] a){
            int min = a[0];
            for (int i = 0; i < a.length; i++) {
                if(min > a[i]){
                   min = a[i];
                }
            }
            return min;
        }
        public static int sum(int a){
            int x,s = 0;
            while(a != 0){
                x = a % 10;
                s = s + x;
                a /= 10;
            }
            return s;
        }
        public static boolean isPrime(int a){
            if(a <= 1)return false;
            else
            for(int i = 2;i <= Math.sqrt(a);i++){
                if(a % i == 0)return false;
            }return true;
        }
    
        public static long qiuYu(long i){
            long a;
            a = i % 10;
            return a;
        }
        public static int daoXu(int x){
            int s = 0,m;
            while(x != 0){
                m = x % 10;
                s = s * 10 + m;
                x /= 10;
            }
            return s;
        }
    
        public static int jiaWei(int x){
            int s = 0,m;
            while(x != 0){
                m = x % 10;
                s = s + m;
                x /= 10;
            }
            return s;
        }
    
        public static int fun(int x){
            if(x == 1 || x == 2)return 1;
            else return fun(x - 1) + fun(x - 2);
        }
    }
    

    Python :

    def zs(n):
      if n==2:
        return 1
      elif n==1:
        return 0
      else:
        for i in range(2,int(n**0.5)+1):
          if n%i==0:
            return 0
        return 1
    
    for i in range(ord('A'),ord('Z')+1):
      if zs(i)==1:
        print(i,chr(i))
    
    for i in range(ord('a'),ord('z')+1):
      if zs(i)==1:
        print(i,chr(i))
        
      
    
    
    • 1

    信息

    ID
    2792
    时间
    1000ms
    内存
    64MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者