When submitting a solution in C++, please select either C++14 (GCC 6-32) or C++17 (GCC 7-32) as your compiler. ×

iamurhater's blog

By iamurhater, history, 7 years ago, In English

Two days ago,I attempted TCS Mockvita contest and couldn't get to any solution during the contest to two problems.Even after the contest,I am unable to solve them.Can anyone help me out? The questions are:-

Question 1.

Consecutive Prime Sum Some prime numbers can be expressed as Sum of other consecutive prime numbers. For example 5 = 2 + 3 17 = 2 + 3 + 5 + 7 41 = 2 + 3 + 5 + 7 + 11 + 13 Your task is to find out how many prime numbers which satisfy this property are present in the range 3 to N subject to a constraint that summation should always start with number 2. Write code to find out number of prime numbers that satisfy the above mentioned property in a given range. Input Format: First line contains a number N Output Format: Print the total number of all such prime numbers which are less than or equal to N. Constraints: 2<N<=12,000,000,000 Sample:

Question 2.

Football League Table Statement : All major football leagues have big league tables. Whenever a new match is played, the league table is updated to show the current rankings (based on Scores, Goals For (GF), Goals Against (GA)). Given the results of a few matches among teams, write a program to print all the names of the teams in ascending order (Leader at the top and Laggard at the bottom) based on their rankings. Rules: : A win results in 2 points, a draw results in 1 point and a loss is worth 0 points. The team with most goals in a match wins the match. Goal Difference (GD) is calculated as Goals For (GF) — Goals Against (GA). Teams can play maximum of two matches against each other — Home and Away matches respectively Ranking is decided as follows Team with maximum points is ranked 1 and minimum points is placed last Ties are broken as follows Teams with same points are ranked according to Goal Difference(GD). If Goal Difference(GD) is same, then team with higher Goals For is ranked ahead If GF are same, the teams should be at the same rank but they should be printed in case-insensitive alphabetic according of the team names. More than 2 matches of same teams, should be considered as Invalid Input A team can't play matches against itself, hence if team names are same for a given match, it should be considered Invalid Input Input Format: First line of input will contain number of teams (N) Second line contains names of the teams (Na) delimited by a whitespace character Third line contains number of matches (M) for which results are available Next M lines contain a match information tuple {T1 T2 S1 S2}, where tuple is comprised of the following information • T1 — Name of the first team • T2 — Name of the second team • S1 — Goals scored by the first team • S2 — Goals scored by the second team Output Format: Team names in order of their rankings, one team per line OR Print "Invalid Input" where appropriate. Constraints: 0< N <=10,000 0<=S1,S2 Example: Consider 5 teams Spain, England, France, Italy and Germany with the following fixtures: Match 1: Spain vs. England (3-0) (Spain gets 2 points, England gets 0) Match 2: England vs. France (1-1) (England gets 1 point, France gets 1) Match 3: Spain vs. France (0-2) (Spain gets 0 points, France gets 2)

Table 1. Points Table after 3 matches

Since, Italy and Germany are tied for points, goals difference is checked. Both have same, so, Goals For is checked. Since both are same. Germany and Italy share the 4th rank. Since Germany appears alphabetically before Italy, Germany should be printed before Italy. Then the final result is: France Spain England Germany Italy Sample:

PS:This is my first time asking a question on Codeforces,Kindly regret if you find any mistakes

  • Vote: I like it
  • -3
  • Vote: I do not like it

| Write comment?
»
7 years ago, # |
Rev. 3   Vote: I like it 0 Vote: I do not like it

For question 1 , I did the following

  1. Pre calculate primes till sqrt(N) , this is because we need maximum x such that p1 + p2 + p3...px <  = n and difference between primes is at least 2. therefore you can lower bound the summation with sum of odd number . Then sum of x consecutive odd numbers is x2.

  2. Now brute force all partial sum of primes and check for the primality of the sum

  3. If you use java you can use the inbuilt function isProbablePrime from BigInteger class (uncertainity of 10 took around 1.5s for the largest test case). Or you could use the sqrt primality testing which took around 3s but it still got accepted.

»
7 years ago, # |
  Vote: I like it 0 Vote: I do not like it

hello

is there any link?

»
6 years ago, # |
Rev. 2   Vote: I like it +1 Vote: I do not like it

wait how did u write the test i mean from where ....?like will you send me the mockvita url...?