The program must accept an integer N as the input. The task is to double the value of every prime digit in N and then append those values to N itself.
Boundary Condition(s):
10 <= N <= 10^8
Input Format:
The first line contains the integer N.
Output Format:
A single line contains the modified number.
Example Input/Output 1:
Input:
4352
Output:
435246
Explanation:
The prime digits in 4352 are 3, 5, and 2. When doubled, they become 6, 10, and 4. Appending 6 and 4 to the original number (since 10 is not a single-digit), we get 435246.
Example Input/Output 2:
Input:
2178
Output:
217842146
Explanation:
The prime digits in 2178 are 2 and 7. When doubled, they become 4 and 14. Appending 4 and both digits of 14 to the original number, we get 217842146.
Example Input/Output 3:
Input:
4910
Output:
491082
Explanation:
The prime digits in 4910 are 4, 9, and 1. None of them are prime numbers, so no digits are appended to the original number. The output remains 4910.
N = input().strip()
prime_digits = {'2', '3', '5', '7'}
appended = ''.join(str(2*int(d)) if d in prime_digits else '' for d in N)
print(N + appended)
#include<stdio.h>
#include<string.h>
int isPrimeDigit(char d) {
return d == '2' || d == '3' || d == '5' || d == '7';
}
int main() {
char N[10];
scanf("%s", N);
printf("%s", N);
for(int i = 0; N[i]; i++) {
if(isPrimeDigit(N[i])) {
printf("%d", 2 * (N[i] - '0'));
}
}
return 0;
}
#include <iostream>
#include <string>
using namespace std;
bool isPrimeDigit(char d) {
return d == '2' || d == '3' || d == '5' || d == '7';
}
int main() {
string N;
cin >> N;
cout << N;
for(char c : N) {
if(isPrimeDigit(c)) {
cout << 2 * (c - '0');
}
}
return 0;
}
import java.util.Scanner;
public class DoublePrimeDigits {
static boolean isPrimeDigit(char d) {
return d == '2' || d == '3' || d == '5' || d == '7';
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String N = sc.next();
System.out.print(N);
for(char c : N.toCharArray()) {
if(isPrimeDigit(c)) {
System.out.print(2 * (c - '0'));
}
}
}
}