{
task6.pas
Copyright 2009 Martin Habovštiak
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.
}
program task6;
var boxes : array[1..30000000] of integer;
l,r,a,b,n,q,i,j,sum :longint;
t :byte;
BEGIN
readln(n,q);
for i:= 1 to q do
begin
read(t);
if t = 1 then
begin
readln(l,r,a,b);
for j:=l to r do boxes[j]:=(j-l+1)*a mod b;
end else
begin
readln(l,r);
sum:=0;
for j:=l to r do sum:=sum + boxes[j];
writeln(sum);
end;
end;
END.