#include <iostream>
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <string.h>
#include <cmath>
#include <bitset>
#include <set>
#include <map>
#include <list>
#define ll long long
const int inf = 0x3f3f3f3f;
const int mod = 1e9;
const ll ds = 1e15+7;
const double p = 3.141592653589793238462643383;
using namespace std;
ll a[100005],tree[400005],lazy[400005],block[100005];
void build(int l,int r,int xb)
{
if(l == r){
tree[xb] = a[l];
lazy[xb] = 0;
return ;
}
int mid = (l+r) >> 1;
build(l,mid,xb*2);
build(mid+1,r,xb*2+1);
tree[xb] = tree[xb*2] + tree[xb*2+1];
}
void pushdown(int l1,int l2,int xb)
{
tree[xb*2] += lazy[xb]*l1;
tree[xb*2+1] += lazy[xb]*l2;
lazy[xb*2] += lazy[xb];
lazy[xb*2+1] += lazy[xb];
lazy[xb] = 0;
}
ll sum(int L,int R,int l,int r,int xb)
{
if(l <= L && r >= R){
return tree[xb];
}
if(r < L || R < l){
return 0;
}
int mid = (L+R) >> 1;
pushdown(mid-L+1,R-mid,xb);
ll res = 0;
if(l <= mid) res += sum(L,mid,l,r,xb*2);
if(r > mid) res += sum(mid+1,R,l,r,xb*2+1);
return res;
}
void update1(int L,int R,int l,int r,int inx,int xb)
{
if(l <= L && r >= R){
tree[xb] += (R-L+1)*inx;
lazy[xb] += inx;
return;
}
int mid = (L+R) >> 1;
pushdown(mid-L+1,R-mid,xb);
if(l <= mid) update1(L,mid,l,r,inx,xb*2);
if(r > mid) update1(mid+1,R,l,r,inx,xb*2+1);
tree[xb] = tree[xb*2+1] + tree[xb*2];
}
int main()
{
int n,m,opt,l,r,x;
scanf("%d%d",&n,&m);
int len = sqrt(n);
for(int i = 1; i <= n; i++) scanf("%d",&a[i]);
build(1,n,1);
while(m--){
scanf("%d",&opt);
if(opt == 1){
scanf("%d%d",&l,&r);
ll res = 0;
res = sum(1,n,l,r,1);
for(int i = 1; i <= len; i++){
res += block[i]*(r/i-(l-1)/i);
}
printf("%lld\n",res);
}
else if(opt == 2){
scanf("%d%d%d",&l,&r,&x);
update1(1,n,l,r,x,1);
}
else{
scanf("%d%d",&l,&x);
if(l <= len) block[l] += x;
else{
for(int i = l; i <= n; i += l){
update1(1,n,i,i,x,1);
}
}
}
}
return 0;
}