C language programming problem: the perfect prime number

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/weixin_40688217/article/details/90300651

Perfect prime number

Time Limit: 1000 ms Memory Limit: 65536 KiB

Problem Description
prime number, also known prime number. Refers to a natural number greater than 1, and the integer 1 except itself, the other can not be a natural number divisible. We define: if a prime number is a perfect prime number if and only if each of its figures and is also a prime number. You are given a positive integer, you need to write a program to determine what this number in accordance with the above definition is not a perfect prime.

Input
input comprising a plurality of sets of test data.
Each test contains only one positive integer n (1 <n <= 10 ^ 6).

Output
For each test, if the prime number n is perfect, the output "YES", and otherwise outputs "NO" (no quotes are output).

Sample Input
11
13
Sample Output
YES
NO

Hint

Source
Qinchuan


Thinking

I started doing this problem too much trouble, is seeking is seeking you-digit number and, in fact, the title has been given a positive integer n (1 <n <= 10 ^ 6), we need not think too much set a1, a2, a3, a4, a5, a6, calculated on the figures you, Ye seek natural sum. It determines whether itself is a prime number for the cycle, and determines whether the sum of the prime numbers for separate write cycles, which are added temp conditions are not met is not a temp.


Reference Code:

#include<stdio.h>
int main()
{
    int a,b,i,sum,a1,a2,a3,a4,a5,a6,j,temp;
    while(scanf("%d",&a) != EOF)
    {
        temp = 1;
        a1 = a % 10;
        a2 = a / 10 % 10;
        a3 = a / 100 % 10;
        a4 = a / 1000 % 10;
        a5 = a / 10000 % 10;
        a6 = a / 100000 % 10;
        sum = a1 + a2 + a3 + a4 + a5 + a6;
        for(i = 2; i <= a - 1; i++){ 
 
            if(a % i == 0)
                temp++;
 		} 
        for(j = 2; j <= sum - 1; j++){ 
                if(sum%j == 0)
                    temp++;
        } 
        if(temp == 1)
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}

Guess you like

Origin blog.csdn.net/weixin_40688217/article/details/90300651