#include <bits/stdc++.h>
//#include <atcoder/all>
#ifndef LOCAL
#pragma GCC target("arch=skylake-avx512")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#endif
using namespace std;

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string &s) {
  return '"' + s + '"';
}

string to_string(const char *s) {
  return to_string((string)s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " +
         to_string(get<3>(p)) + ")";
}

void debug_out() {
  cerr << endl;
}

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-12;
static const double PI = acos(-1.0);

#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define dbg(...) 42
#endif

const int MAX = 1'000'001;

bool is_prime[MAX + 1];
int min_factor[MAX + 1];
vector<int> primes;

ll f(ll y, ll R, ll i) {
  return R / y - i / y;
}

void solve(long long L, long long R) {
  fill_n(is_prime, MAX + 1, true);
  is_prime[0] = is_prime[1] = false;
  min_factor[0] = 0;
  min_factor[1] = 1;
  for (int i = 2; i <= MAX; ++i) {
    if (is_prime[i]) {
      min_factor[i] = i;
      for (long long j = static_cast<long long>(i) * i; j <= MAX; j += i) {
        is_prime[j] = false;
        if (min_factor[j] == 0)
          min_factor[j] = i;
      }
    }
  }
  ll ans = 0;
  FOR(i, max(2ll, L), R) {
    set<ll> s;
    auto j = i;
    while (j > 1) {
      auto k = min_factor[j];
      s.insert(k);
      j = j / k;
    }
    vector<ll> v(s.begin(), s.end());
    ll a = -f(i, R, i);
    FOR(k, 1, 1 << v.size()) {
      int count = __builtin_popcount(k);
      ll y = 1;
      REP(l, v.size()) {
        if ((k >> l) & 1) {
          y *= v[l];
        }
      }
      a += (count % 2 == 1 ? +1 : -1) * f(y, R, i);
    }
    ans += a;
  }
  cout << ans * 2 << endl;
}

int main() {
  long long L;
  std::scanf("%lld", &L);
  long long R;
  std::scanf("%lld", &R);
  solve(L, R);
  return 0;
}

#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define SHOW1d(v,n) {REP(W,n)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {REP(aaa,i){REP(bbb,j)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007LL

typedef long long ll;
typedef pair<ll,ll> P;

template<typename T>
void show_vector(vector<T> v) {
	for (auto ele: v)cout << ele << " " ;cout << endl;
}

template<typename T>
void show_vector(vector<vector<T>> v) {
	for (auto ele: v)show_vector(ele);
}

template<typename T>
void show_vector(vector<vector<vector<T>>> v) {
	for (auto ele: v) {
		show_vector(ele);
		cout << endl;
	}
}

vector<vector<P>> v(200200);
ll mp[2];
ll ans;

void dfs(int now, int pre, ll val, ll shift) {
	mp[val > 0]++;
	REP(i, v[now].size()) {
		if (v[now][i].FI == pre) continue;
		dfs(v[now][i].FI, now, val ^ (v[now][i].SE & (1LL << shift)), shift);
	}
}

int main(){
	cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);

	ll n;cin >> n;
	REP(i, n-1) {
		ll a, b, w;cin >> a >> b >> w;
		a--;b--;
		v[a].EB(b, w);
		v[b].EB(a, w);
	}

	REP(i, 60) {
		mp[0] = 0;
		mp[1] = 0;
		dfs(0, -1, 0, i);
		ans += ((1LL << i) % MOD) * (mp[0] * mp[1] % MOD) % MOD;
		ans %= MOD;
	}

	cout << ans << endl;

	return 0;
}
