Question

In: Computer Science

Lili was working on her mathematic homework, and suddenly, she found another classic problem. The problem...

Lili was working on her mathematic homework, and suddenly, she found another classic problem.

The problem is: “Given three light bulbs X , Y , and Z. Bulb X light up every A seconds, bulbs Y light up

every B seconds, and bulb Z light up every C seconds. If three bulbs light up together for the 1-st

time at 0-th second, the 2-nd time this three bulbs will light up together at the same time will be at

K1-th second. Find K1!”

Lili got bored by this question. Lili challenge herself and she figured out a challenging problem. She

wants to find the sum of all Ki which satisfy L ≤ Ki ≤ R, where when at Ki-th seconds, the three bulbs

light up together for the i + 1-th time. Solve Lili’s challenge!

Format Input :

There are T testcases. Every testcase consists of five integers A , B , C , L, and R as described above.

Format Output:

Output T testcases with format “Case # X: ”, where X indicates the testcase number and then

followed by an integer indicates the answer to Lili’s challenge.

Constraints:

• 1 ≤ T ≤ 10

• 1 ≤ A, B, C ≤ 100

• 1 ≤ L ≤ R ≤ 109

Sample Input (standard input):

5

1 2 3 1 20

2 3 5 30 30

2 3 5 30 90

11 11 11 10 40

2 3 4 10 30

Sample Output (standard output):

Case #1: 36

Case #2: 30

Case #3: 180

Case #4: 66

Case #5: 36

NOTE: USE C LANGUAGE, DONT USE FUNCTION(RESULT,RETURN),VOID,RECURSIVE,

USE BASIC CODE AND CODE IT UNDER int main (){, constraint must be the same.

Solutions

Expert Solution

: : C code : :

#include <stdio.h>
int main()
{
  int lcm,sum,st,size,i,m,l,r,t,p;
  p=0;
  scanf("%d",&t);
  while(t>0)
  {
      p++;
      t--;sum=0;
      int arr[3];
      scanf("%d %d %d %d %d",&arr[0],&arr[1],&arr[2],&l,&r);
      size = 3;//sizeof(arr) / sizeof(int);
      lcm = arr[0];
      //calculating lcm of 3 numbers
      for (i = 1; i < size; i++){
        m=1;
        while( m%lcm || m%arr[i]) m++;
        lcm = m;
      }
      //finding starting index to start sum from for lcm multiple 
      if(l>= lcm) st=l/lcm;
      else st=1;
      
      for(i=st; lcm*i <= r ; i++ ){
          sum+=lcm*i;
      }
      printf("Case #%d: %d\n",p,sum);
  }return 0;
}

Algorithm

- We basically have to find the lcm of A,B,C ; first ,

-Then sum up multiples of lcm that lie in the range [L,R]

: : Sample output : :

Please refer to the screenshot of the code to understand the indentation of he code:


Related Solutions

2. Jolene wakes suddenly to her alarm clock and realizes that she is late for her...
2. Jolene wakes suddenly to her alarm clock and realizes that she is late for her 9:15am CBIO2210 class. She jumps to her feet, feels dizzy and lightheaded for a moment, then hops into the shower. Draw a diagram / flowchart / picture of the sequence of events that occurred when she jumped up that overcame her dizzy feeling and prevented her from losing consciousness. Include the receptors, the control center, at least one effector site, information traveling between receptors...
A college student is working on her physics homework in her dorm room. Her room contains...
A college student is working on her physics homework in her dorm room. Her room contains a total of 7.0 ×1026 gas molecules. As she works, her body is converting chemical energy into thermal energy at a rate of 110 Watt . PART A If her dorm room were an isolated system (dorm rooms can certainly feel like that) and if all of this thermal energy were transferred to the air in the room, by how much would the temperature...
A woman aged 28 years is in labour when she suddenly collapses. This is her fourth...
A woman aged 28 years is in labour when she suddenly collapses. This is her fourth pregnancy and she has had three previous spontaneous vaginal deliveries at term. This pregnancy has been uncomplicated and she has been admitted with contractions at 37 weeks and 6 days. On arrival on the labour ward the fetus was palpated to be normal size, cephalic and 3/5 palpable abdominally. The cervix was 3 cm dilated and the membranes were intact. Blood pressure and urinalysis...
This is a classic retirement problem. A friend is celebrating her birthday and wants to start...
This is a classic retirement problem. A friend is celebrating her birthday and wants to start saving for her anticipates retirement. She has the following years to retirement and retirement spending goals: Years until retirement: 30 Amount to withdraw each year: 90,000 Years to withdraw in retirement: 20 Interest Rate: 8% Because your friend is planning ahead, the first withdraw will not take place until one year after she retires. She wants to make an equal annual deposit into her...
A 23-year-old felt puffy, weak, and tired for several months. She suddenly noticed her urine had...
A 23-year-old felt puffy, weak, and tired for several months. She suddenly noticed her urine had a red to brown discoloration and the volume was minimal. She went to the emergency room of a nearby hospital and the following data were obtained upon examination and testing: Hematology: Serum sodium 125 mEq/L Serum potassium 6 mEq/L Serum creatinine 2.6 mg/dL BUN 24.0 mg/dL pH (arterial) 7.32 Hematocrit 25% Urinalysis: Appearance Red to brown Specific gravity 1.025 Blood Positive Glucose Negative Protein...
1. Morgan was working out and she noticed that a portion of her leg did not...
1. Morgan was working out and she noticed that a portion of her leg did not sweat. The lack of sweat from that area could potentially be due to what type of gland not developing properly?        Exocrine         Endocrine         Unicellular 2. Which of the following is responsible for the synthesis of cerebrospinal fluid (CSF)?        Microglial         Ependymal cells         Osteoblast         Medulla Oblongata         Insula 3. What condition is...
I’m working on an ANOVA homework problem, I have 5 group’s individual income based on their...
I’m working on an ANOVA homework problem, I have 5 group’s individual income based on their years of education. (<12, 12, 13-15, 16 and 16+). Here is the problem: Use an extra sum of squares F-test (BYOA: Build Your Own ANOVA!) to use all the data (to increase the degrees of freedom and thus the power of the test!) to compare only the bachelor’s degree group (16) income to the more than bachelor’s degree group (>16) income.Show your final ANOVA...
Leshonda had been working at her job for almost twenty years. She felt like she worked...
Leshonda had been working at her job for almost twenty years. She felt like she worked overtime more often than not and deserved a raise, so she randomly selected 50 paychecks and found that she had worked overtime in 32 of those weeks. Use a TI-83, TI-83 plus, or TI-84 calculator to test whether Leshonda worked overtime more often than not. Identify the p-value, rounding to three decimal places. PLEASE SHOW ON THE STEPS ON THE CALCULATOR, THANK YOU!
A friend of yours says that she has found a lump in her breast. List steps...
A friend of yours says that she has found a lump in her breast. List steps that she would take from initial types of diagnostic testing to surgery to treatment for stage 3 breast cancer. What types of complementary medicine or dietary and lifestyle changes can she make to improve her chances of beating this cancer.
Andrea is an employee of Fern Corporation. She also has her own business working as a...
Andrea is an employee of Fern Corporation. She also has her own business working as a life coach. For 2017, Andrea’s wages from Fern were $210,000. Her self-employment income was $30,000 (line 4, Form SE, based on 92.35% of net earnings as a life coach). If required, round any computations to two decimal places. Round final answers to the nearest dollar. a. Compute the payroll, self-employment, and additional Medicare taxes for Andrea for 2017. $______ b. Assume the same facts...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT