codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

678C.md (1357B)


      1 Source: https://codeforces.com/problemset/problem/678/C
      2 
      3 C. Joty and Chocolate
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 Little Joty has got a task to do. She has a line of *n* tiles indexed from 1 to *n*. She has to paint them in a strange pattern.
     22 
     23 An unpainted tile should be painted Red if it's index is divisible by *a* and an unpainted tile should be painted Blue if it's index is divisible by *b*. So the tile with the number divisible by *a* and *b* can be either painted Red or Blue.
     24 
     25 After her painting is done, she will get *p* chocolates for each tile that is painted Red and *q* chocolates for each tile that is painted Blue.
     26 
     27 Note that she can paint tiles in any order she wants.
     28 
     29 Given the required information, find the maximum number of chocolates Joty can get.
     30 
     31 Input
     32 
     33 The only line contains five integers *n*, *a*, *b*, *p* and *q* (1 ≤ *n*, *a*, *b*, *p*, *q* ≤ 109).
     34 
     35 Output
     36 
     37 Print the only integer *s* — the maximum number of chocolates Joty can get.
     38 
     39 Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.
     40 
     41 Examples
     42 
     43 Input
     44 
     45 ```
     46 5 2 3 12 15
     47 ```
     48 
     49 Output
     50 
     51 ```
     52 39
     53 ```
     54 
     55 Input
     56 
     57 ```
     58 20 2 3 3 5
     59 ```
     60 
     61 Output
     62 
     63 ```
     64 51
     65 ```