本蒟蒻很蒟, 如有问题请评论

#A. 判断质数

#include<bits/stdc++.h> // 万能头

using namespace std; 

bool isPrime(int x){ // 判断素数函数
    for (int i = 2; i * i <= x ; i++){
        if (x % i == 0){
            return false;
        }
    }
    return true;
}

int main(){
    int n, ret;
    scanf("%d", &n);
    ret = isPrime(n);
    if (ret){ // 
        printf("True");
    } else {
        printf("False");
    }
    return 0;
}

#B. 交换两位数

#include<bits/stdc++.h> // 这题太水了, 用string做吧

using namespace std;

string s;

int main(){

    cin >> s;

    cout << s[1] << s[0];

    return 0;
}

#C. 辗转相除法

#include<bits/stdc++.h>  // 这题也挺水了

using namespace std;

int gcd(int a, int b){ // 辗转相除法递归函数
    if(b==0)
        return a;
    return gcd(b,a%b);
}

int main(){
    int a, b, ret;
    scanf("%d%d", &a, &b);
    ret = gcd(a, b);
    printf("%d", ret);
    return 0;
}

#D. 入门测试题目

#include<bits/stdc++.h> // a + b what?

using namespace std;

struct node{ // 结构体
	long long number; // 数
	void in(){  // 输入
		scanf("%lld", &number);
	}
	void out(){ // 输出
		printf("%lld", number);
	}
};

node operator + (node a,node b){ // 重载运算符
	node c;
	c.number = a.number + b.number;
	return c;
}

int main(){
	node a, b, c;
	a.in();
	b.in();
	c = a + b;
	c.out();
	return 0;
}

#E. 合数求和

#include<bits/stdc++.h> // 万能头

using namespace std; 

bool isPrime(int x){ // 判断素数函数
    for (int i = 2; i * i <= x ; i++){
        if (x % i == 0){
            return false;
        }
    }
    return true;
}

int main(){
    int n;
    scanf("%d", &n);
    
    int cnt = 0;
    for (int i = 4; i <= n; i++){
        if (isPrime(i) == false){
     
            cnt+=i;
        }
    }
    printf("%d", cnt);
    return 0;
}

1 条评论

  • @ 2023-9-27 19:32:32

    雀氏题特水,这只是个测试😄

    • @ 2023-9-27 22:23:41

      你终于来啦, 我还以为网站要凉了

  • 1