`{"id":"7bfd851e-ffbd-4c15-aa66-8ed57113282b","name":"Multiples Of 3","description":"There are N numbers(indexed from 1 to N) initially all are 0.\r\nYou have to perform Q operations of two types:\r\n1. 1 A B: increase all numbers in range from index A to B by 1.\r\n2. 2 A B: count how many numbers in range from index A to B are divisible by 3.","inputFormat":"First line contains one integer N\r\nSecond line contains one integer Q\r\nfollowing Q lines contains queries of format either :\r\n1 A B or \r\n2 A B","outputFormat":"for all query of type 2 A B print in seperate lines count of numbers.","constraints":"1. 1 &lt;= N &lt;= 10^5\r\n2. 1 &lt;= A &lt;= B &lt;= N","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static void main(String[] args) throws Exception {\r\n BufferedReader read = new BufferedReader(new InputStreamReader(System.in));\r\n\r\n int n = Integer.parseInt(read.readLine());\r\n int q = Integer.parseInt(read.readLine());\r\n\r\n // write your code here\r\n\r\n\r\n }\r\n}\r\n"},"ruby":{"code":""},"python":{"code":""},"javascript":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"4\r\n7\r\n2 1 4\r\n1 2 3\r\n1 2 4\r\n2 1 1\r\n1 1 4\r\n2 4 4\r\n2 1 4\r\n","sampleOutput":"4\r\n1\r\n0\r\n2\r\n","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"9b3d7d76-b2ca-458f-80a8-4b37d548024a","name":"Segment Tree For Experts","slug":"segment-tree-for-experts-953","type":0},{"id":"d9f9a7f2-4b92-434b-8a57-8746d6170251","name":"Multiples Of 3","slug":"multiples-of-3","type":1}],"next":{"id":"9c7b50cd-8df3-4aff-b492-b2e6316f4682","name":"K Increasing Subsequence 1","type":1,"slug":"k-increasing-subsequence-1"},"prev":{"id":"5eceac13-61e9-4d38-960d-7b16abd79154","name":"Prime Divide","type":1,"slug":"prime-divide"}}}`

# Multiples Of 3

There are N numbers(indexed from 1 to N) initially all are 0. You have to perform Q operations of two types: 1. 1 A B: increase all numbers in range from index A to B by 1. 2. 2 A B: count how many numbers in range from index A to B are divisible by 3.

`{"id":"7bfd851e-ffbd-4c15-aa66-8ed57113282b","name":"Multiples Of 3","description":"There are N numbers(indexed from 1 to N) initially all are 0.\r\nYou have to perform Q operations of two types:\r\n1. 1 A B: increase all numbers in range from index A to B by 1.\r\n2. 2 A B: count how many numbers in range from index A to B are divisible by 3.","inputFormat":"First line contains one integer N\r\nSecond line contains one integer Q\r\nfollowing Q lines contains queries of format either :\r\n1 A B or \r\n2 A B","outputFormat":"for all query of type 2 A B print in seperate lines count of numbers.","constraints":"1. 1 &lt;= N &lt;= 10^5\r\n2. 1 &lt;= A &lt;= B &lt;= N","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static void main(String[] args) throws Exception {\r\n BufferedReader read = new BufferedReader(new InputStreamReader(System.in));\r\n\r\n int n = Integer.parseInt(read.readLine());\r\n int q = Integer.parseInt(read.readLine());\r\n\r\n // write your code here\r\n\r\n\r\n }\r\n}\r\n"},"ruby":{"code":""},"python":{"code":""},"javascript":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"4\r\n7\r\n2 1 4\r\n1 2 3\r\n1 2 4\r\n2 1 1\r\n1 1 4\r\n2 4 4\r\n2 1 4\r\n","sampleOutput":"4\r\n1\r\n0\r\n2\r\n","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"9b3d7d76-b2ca-458f-80a8-4b37d548024a","name":"Segment Tree For Experts","slug":"segment-tree-for-experts-953","type":0},{"id":"d9f9a7f2-4b92-434b-8a57-8746d6170251","name":"Multiples Of 3","slug":"multiples-of-3","type":1}],"next":{"id":"9c7b50cd-8df3-4aff-b492-b2e6316f4682","name":"K Increasing Subsequence 1","type":1,"slug":"k-increasing-subsequence-1"},"prev":{"id":"5eceac13-61e9-4d38-960d-7b16abd79154","name":"Prime Divide","type":1,"slug":"prime-divide"}}}`

Editor

# Multiples Of 3

medium

There are N numbers(indexed from 1 to N) initially all are 0. You have to perform Q operations of two types: 1. 1 A B: increase all numbers in range from index A to B by 1. 2. 2 A B: count how many numbers in range from index A to B are divisible by 3.

## Constraints

1. 1 <= N <= 10^5 2. 1 <= A <= B <= N

## Format

### Input

First line contains one integer N Second line contains one integer Q following Q lines contains queries of format either : 1 A B or 2 A B

### Output

for all query of type 2 A B print in seperate lines count of numbers.

## Example

Sample Input

```.css-23h8hz{color:inherit;font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;}4 7 2 1 4 1 2 3 1 2 4 2 1 1 1 1 4 2 4 4 2 1 4 ```

### Sample Output

```.css-3oaykw{color:var(--chakra-colors-active-primary);font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;font-family:Monospace;}4 1 0 2 ```

Discussions

Show Discussion

Related Resources