Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Prime Triangle
- Description
- We know that you love math, so we have prepared a very interesting task, that involves both geometry and prime numbers.
- By a given N number, from which you need to generate a sequence of 1 to N inclusive. For every prime number in that sequence, you need to print out all the other numbers before it (and the number itself), whether they are prime or not
- Note:
- For the purposes of this task (and against the laws of mathematics), the number 1 is considered as prime.
- Example
- Let's say N=10
- We have the sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- The prime numbers are 1, 2, 3, 5, 7 - 5 prime numbers, so we prive 5 rows
- Each row contains all the numbers for 1 to PRIME_NUMBER
- Result:
- 1
- 1 2
- 1 2 3
- 1 2 3 4 5
- 1 2 3 4 5 6 7
- Lets make things simpler:
- Print 0 if the numbers is not prime
- Print 1 if the number is prime
- Final result:
- 1
- 1 1
- 1 1 1
- 1 1 1 0 1
- 1 1 1 0 1 0 1
- Input
- Read from the standard input
- On the single line, find the number N
- The input data will always be valid and in the format described. There is no need to check it explicitly
- Output
- Print on the standard output
- The output should consist of several lines of digits each of which can be either 1 or 0
- Without any space between them
- Sample tests
- Input
- 10
- Output
- 1
- 11
- 111
- 11101
- 1110101
- Input
- 27
- Output
- 1
- 11
- 111
- 11101
- 1110101
- 11101010001
- 1110101000101
- 11101010001010001
- 1110101000101000101
- 11101010001010001010001
- Word Anagrams
- You are given a word and a list of words. Your task is to check whether all the words from the list are anagrams of the word.
- An anagram is a word formed by rearranging the letters of another word:
- The following are anagrams of "anagram":
- "gramana", "aaagrnm", "margana", etc..
- The following are NOT anagrams of "anagram":
- "aanagram", "aaagram", "anagra", "anagrama", "yxy"
- Input
- Read from the standard input
- On the first line, find W - the word to check against;
- On the second line, find N - the number of words in the list of words WORDS;
- On the next N lines, the words from WORDS;
- Output
- Print to the standard output
- For each word from WORDS print either:
- "Yes", if the word is an anagram of W;
- "No", if the word is NOT an anagram of W;
- Sample tests
- Input
- anagram
- 6
- gramana
- aaagrnm
- anagra
- margana
- abc
- xy
- Output
- Yes
- Yes
- No
- Yes
- No
- No
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement