PRIME-QUINE

http://www.codechef.com/CDGF2013/problems/PRQUIN

Omrita is all determined to learn programming. This semester she is taking “Introduction to C programming”. Being a bright student she quickly covered the basics and managed to finish all the assignments way before the dead line. Her Instructor is very impressed by her work and decided to give her some more assignment. A typical assignment on C programming is:

Write a C program that takes an positive integer as input and determines whether it is a prime or not. If it is a prime output “YES” else output “NO”.

Of-course this is very easy for Omrita. So her instructor modified the assignment. Now, if an composite number is encountered in the input, instead of printing “NO” the
program should behave like a quine i.e output itself.

Omrita have no clue about writing quine. Hence, she asked for your help.

Input

A line contains an integer N.

Output

The required string described above.

Constraints

1 ≤ N ≤ 10000

Example

Input:

7

Source

abcde

Output:

YES

Score:

5

Input:

64

Source:

abcde

Output:

abcde

Score:

5

Explanation

Example
case 1: 7 is a prime number, hence the output “YES” (quotes for clarity).
case 2: 64 is not a prime number, hence the output is the program (source) itself.

WHEN I TRIED TO SOLVE THIS I TRAPPED IN RECURSIVE PRINTING.

PLEASE HELP ME IN WRITING QUINE.

2 Likes

A simple google search would lead you to this page

Basically you keep a placeholder for your source code (%s in printf) and pass it to itself to get the recursion you need

thanks…for helping me…

//