4 views

Uploaded by SpeedTouch

- Batch10 Computer Appl in Business COURSE PLAN
- Cse Final Learn
- dismissal duty
- Gaudette_HPCA_2016
- My Learning Jigsaw for Maths Level 4
- APPLICATION FORM FOR FREE / AT CONCESSION COMPUTER EDUCATION
- Unit 2.docx
- Untitled
- What computer use.doc
- Não é possível que alguém tenha upado isso
- 10 Challenging Star Pattern Programs in C _ Interview Mantra
- lesson 1 comparing fractions and decimals
- Ito Na Talaga
- Definitions
- English Glossary
- Computer Awareness Full Marks Bits
- btt1o madeup numbers, first name az
- Lesson 7
- CFP_IEEE_TC
- computer basics vocabulary list

You are on page 1of 2

560 Magic

A well known big computer factory is involved in a very secret project. The project is so secret

that we cannot tell you the name of the manufacturer, but we can tell you something about the

project. It is called: the Non-Deterministic Magic Holistic New Age Computer (NDMHNAC). It is

a major breakthrough in thinking about computing, in that it steps away from every traditional idea

in Computer Science and Hardware Design. One of the (many) abilities of NDMHNAC is to execute

calculations with very large numbers very fast.

Unfortunately it has a small
aw. Its circuits are based on Magic, so its calculations are disturbed

by magic in the same way as traditional circuits are disturbed by electromagnetic elds. As you know

the numbers 3 and 7 have strong magic. Therefore these numbers should be avoided, because they

will disturb, and eventually destroy the circuits of the machine. The algorithms used internally in the

machine never generate oending numbers. The only problem is to ban oending numbers from input.

To that purpose a conventional machine is used as a pre-processor. This machine should transform

oending numbers to admissible numbers. (You might wonder how a computer can give a correct

answer if you jumble its input. Now this question shows how much you are tied to traditional thinking

in computer science. A Non-Deterministic Magic Holistic New Age Computer will give correct answers,

even if the input is wrong! (Compare this to traditional computers giving wrong answers, even if the

input is correct!)).

Numbers are arbitrarily large, non-negative integers, in decimal representation. A number is oend-

ing if it has one of the following properties:

it is divisible by 3, or by 7 (e.g. 6, 14, 21),

a 3 or 7 occurs in its decimal representation, (e.g. 13, 27, 37),

a digit is repeated 3 or 7 times consecutively in its decimal representation. (e.g. 2411145,

10000000).

(NB: the number 0 turns out not to be oending).

Oending numbers are to be transformed into non-oending numbers, using (repeatedly) the fol-

lowing rules:

if a number is divisible by 3: divide it by 3

if a number is divisible by 7: divide it by 7

if a 3 occurs in the decimal representation: remove this 3 (remove if possible leading zeros)

if a 7 occurs in the decimal representation: remove this 7 (remove if possible leading zeros)

if a substring of 3 times the same digit occurs in the decimal representation: remove it (remove

if possible leading zeros)

if a substring of 7 times the same digit occurs in the decimal representation: remove it (remove

if possible leading zeros)

if eventually no digit is left, consider this as the number 0.

ACM Contest Problems Archive University of Valladolid (SPAIN)

A traditional programmer is hired to implement these rules. After reading the specication given

above, he complains that it is highly ambiguous. For example, the third rule is about removing a 3.

Should all occurrences of 3 be removed, or just any, or only the rst one? Moreover, should every rule

be applied repeatedly, or should all rules be applied, and then all rules again, and in which order?

Dierent interpretations of the specication may give rise to thousands of dierent answers.

The designers of the new machine declare that they do not care, as long as a non-oending number

is obtained. Seeing that the programmer feels really uncomfortable, they say: 'OK, just give us the

largest possible answer'. The programmer got himself an other job.

Write a program which, given a number, generates the largest non-oending number that can be

obtained by applying the rules given above.

Input

The rst line of the input-le contains the number of problems n. The next n lines contain one number

each. An input line is never longer than 21 characters (21 = 3 7). An input line never starts with 0.

Output

The outputle consists of n lines with on each line the largest non-oending number that can be obtained

by applying the rules given above.

Sample Input

3

999

273

2331

Sample Output

11

2

11

- Batch10 Computer Appl in Business COURSE PLANUploaded byArun B Vijay
- Cse Final LearnUploaded bySundar Rajadurai
- dismissal dutyUploaded byapi-280863641
- Gaudette_HPCA_2016Uploaded byAggelos Mich
- My Learning Jigsaw for Maths Level 4Uploaded byideas_factory
- APPLICATION FORM FOR FREE / AT CONCESSION COMPUTER EDUCATIONUploaded byChristopher Kirk
- Unit 2.docxUploaded byssbmashuk
- UntitledUploaded byapi-174391216
- What computer use.docUploaded byadundut
- Não é possível que alguém tenha upado issoUploaded byJoão Guilherme
- 10 Challenging Star Pattern Programs in C _ Interview MantraUploaded byarasurrk
- lesson 1 comparing fractions and decimalsUploaded byapi-261672217
- Ito Na TalagaUploaded byYhelLappay
- DefinitionsUploaded bymuralijagan123
- English GlossaryUploaded byaaron
- Computer Awareness Full Marks BitsUploaded byp4u1991
- btt1o madeup numbers, first name azUploaded byapi-287412963
- Lesson 7Uploaded byNguyen Giang
- CFP_IEEE_TCUploaded bydawoodk
- computer basics vocabulary listUploaded byapi-239203539
- PhysicsUploaded bymeagain153
- computer basics vocabulary listUploaded byapi-239451828
- computer basics vocabulary listUploaded byapi-239451741
- Impact of Computer on SocietyUploaded byraheel
- Computer DefinitionUploaded byPastidyuso C. Ninz
- Martin Caidin - The God MachineUploaded byLogan Blackstone
- computer basics vocabulary listUploaded byapi-239451741
- Bec Higher 04WUploaded byMarta Sousa
- 1500 Computer Awareness Bits for IBPSUploaded byKalyan Tirunagari
- Tutor 3Uploaded byHafiz Vs Haffizie

- Atualização Pirelli Pdg Tef Bre 4.06l.2.00102Uploaded bySpeedTouch
- conception game.txtUploaded bySpeedTouch
- conception game.txtUploaded bySpeedTouch
- Bolo Toalha FelpudaUploaded bySpeedTouch
- Bolo IndianoUploaded bySpeedTouch
- Exercicios AnaUploaded bySpeedTouch
- Receita BoloUploaded bySpeedTouch
- Receita BoloUploaded bySpeedTouch
- testeUploaded bySpeedTouch
- Treino 1,75Uploaded bySpeedTouch

- CBSE CBSE Class 9 NCERT Solution Mathematics Number SystemUploaded bykeertimmunish
- w6Uploaded byPooja Sinha
- Calculus.pdfUploaded byfithriyah
- UntitledUploaded byapi-234166806
- Exemplar Problems - Ch (1)Uploaded byayushtheking11
- Some Comments on Teaching the Decimal Representations of Real Numbers at SchoolUploaded bytrampampam
- ieep201Uploaded byJOSEPH HERBERT MABEL
- 10th Class-Maths Text Book-NewUploaded byVishnu Muddasani
- Maths EmUploaded byRaju Raju
- 1_Number System (Maths)Uploaded byVaibhav Tripathi
- X CBSE Maths Sem 01.pdfUploaded byShubham Karande
- Chapter-1Uploaded bySuraj Chaurasia
- The Use of Euclids Division Lemma to Prove Mathematical RelationshipsUploaded bysubhro66
- notes-ma131_ch6.pdfUploaded byXcalibur1101