4 solutions

  • 0
    @ 2024-11-8 13:59:45

    #include #include using namespace std; int isprime(long long k) { long long i; if(k<=1){ return 0; } else if(k<=3){ return 1; } else if(k%20||k%30){ return 0; } else{ for(i=5;ii<=k;i+=6){ if(k%i==0||k%(i+2)==0){ return 0; } } } return 1; } int main() { int t; long long a,b; cin>>t; while(t--){ cin>>a>>b; if(isprime(ab)){ cout<<"YES\n"; } else{ cout<<"NO\n"; } } return 0; }

    • 0
      @ 2022-3-10 19:24:23
      //素数只有1与它本身能是它因数,所以a和b中肯定有一个是1,另外一个肯定是素数。
      #include <stdio.h>
      #include <algorithm>
      #include <math.h>
      #include <vector>
      #include <iostream>
      #include <string.h>
      #include <queue>
      using namespace std;
      int n;
      long long a,b;
      int main() {
          scanf("%d",&n);
          while(n--) {
              scanf("%lld%lld",&a,&b);
              int k=0;
              if(a==1) {
                  for(int i=2; i<=sqrt(b); i++)
                      if(b%i==0) {
                          puts("NO");
                          k=1;
                          break;
                      }
                  if(k==0)
                      puts("YES");
              } else if(b==1) {
                  for(int i=2; i<=sqrt(a); i++)
                      if(a%i==0) {
                          puts("NO");
                          k=1;
                          break;
                      }
                  if(k==0)
                      puts("YES");
              } else {
                  k=1;
                  puts("NO");
              }
          }
          return 0;
      }
      
      • 0
        @ 2022-3-2 16:08:27
        #include<iostream>
        #include<cmath>
        #include<cstdio>
        using namespace std;
        #define ll long long
        
        bool isPrime(ll n){
        	if(n==2)	return true;
        	for(ll i=2;i*i<=n;i++){
        		if(n%i==0)
        			return false;
        	}
        	return true;
        }
        
        int main(){
        	int t;
        	ll x,y;
        
        	scanf("%d",&t);
        	while(t--){
        		scanf("%lld%lld",&x,&y);
        
        		if(isPrime(x*y))
        			cout<<"YES\n";
        		else
        			cout<<"NO\n";
        	}
        
        	return 0;
        }
        
        • 0
          @ 2022-2-10 20:36:21
          #include <stdio.h>
          #include <math.h>
          int main(){
          	int T;
          	long a,b;
          	int flag = 0;
          	long temp;
          	long sum;
          	scanf("%d",&T);
          	for(int i=0; i<T; i++){
          		flag = 0;
          		scanf("%ld %ld",&a,&b);
          		if((a!=1 && b!=1) || (a==1 && b==1)){
          			flag = 1;
          		}
          		else{
          		    if(a!=1){
          		       sum = a*b;
          		       temp = (long)sqrt((double)sum);
          			   for(int i=2; i<=temp; i++){
          			       if(sum%i == 0){
          			       	 flag = 1;
          			       	 break;
          				   }	
          			   }	
          			}
          			else if(b!=1){
          				sum = a*b;
          				temp = (long)sqrt((double)sum);
          				for(int i=2; i<=temp; i++){
          					if(sum%i == 0){
          						flag = 1;
          						break;
          					}
          				}
          			}
          		}
          		if(flag){
          			printf("NO\n");
          		}
          		else
          		printf("YES\n");
          	}
          }
          
          • @ 2022-2-10 20:37:02

            只有当1乘以一个素数时结果才会素数

        • 1

        Information

        ID
        22
        Time
        1000ms
        Memory
        256MiB
        Difficulty
        8
        Tags
        # Submissions
        723
        Accepted
        104
        Uploaded By