#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, c, m;
cin >> n >> c >> m;
vector<int> cnt(n + 1);
for (int i = 0; i < m; i++) {
int l, r;
cin >> l >> r;
cnt[l - 1]++;
cnt[r]--;
}
for (int i = 0; i < n - 1; i++) {
cnt[i + 1] += cnt[i];
}
vector<vector<double>> f(m + 1, vector<double>(c));
f[0][1] = 1.0;
for (int i = 0; i < m; i++) {
for (int a = 0; a < c; a++) {
f[i + 1][a] += f[i][a] * 0.5; // 不涂色
for (int b = 0; b < c; b++) {
f[i + 1][a * b % c] += f[i][a] * 0.5 / c; // 涂了颜色
}
}
}
double ans = 0.0;
for (int i = 0; i < n; i++) {
int cc = cnt[i];
for (int j = 0; j < c; j++) {
ans += f[cc][j] * j;
}
}
cout << fixed << setprecision(3) << ans << '\n';
cerr << "Time: " << double(clock()) / CLOCKS_PER_SEC << '\n';
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG1haW4oKSB7CiAgaW9zOjpzeW5jX3dpdGhfc3RkaW8oZmFsc2UpOwogIGNpbi50aWUobnVsbHB0cik7CiAgaW50IG4sIGMsIG07CiAgY2luID4+IG4gPj4gYyA+PiBtOwogIHZlY3RvcjxpbnQ+IGNudChuICsgMSk7CiAgZm9yIChpbnQgaSA9IDA7IGkgPCBtOyBpKyspIHsKICAgIGludCBsLCByOwogICAgY2luID4+IGwgPj4gcjsKICAgIGNudFtsIC0gMV0rKzsKICAgIGNudFtyXS0tOwogIH0KICBmb3IgKGludCBpID0gMDsgaSA8IG4gLSAxOyBpKyspIHsKICAgIGNudFtpICsgMV0gKz0gY250W2ldOwogIH0KICB2ZWN0b3I8dmVjdG9yPGRvdWJsZT4+IGYobSArIDEsIHZlY3Rvcjxkb3VibGU+KGMpKTsKICBmWzBdWzFdID0gMS4wOwogIGZvciAoaW50IGkgPSAwOyBpIDwgbTsgaSsrKSB7CiAgICBmb3IgKGludCBhID0gMDsgYSA8IGM7IGErKykgewogICAgICBmW2kgKyAxXVthXSArPSBmW2ldW2FdICogMC41OyAvLyDkuI3mtoLoibIKICAgICAgZm9yIChpbnQgYiA9IDA7IGIgPCBjOyBiKyspIHsKICAgICAgICBmW2kgKyAxXVthICogYiAlIGNdICs9IGZbaV1bYV0gKiAwLjUgLyBjOyAvLyDmtoLkuobpopzoibIKICAgICAgfQogICAgfQogIH0KICBkb3VibGUgYW5zID0gMC4wOwogIGZvciAoaW50IGkgPSAwOyBpIDwgbjsgaSsrKSB7CiAgICBpbnQgY2MgPSBjbnRbaV07CiAgICBmb3IgKGludCBqID0gMDsgaiA8IGM7IGorKykgewogICAgICBhbnMgKz0gZltjY11bal0gKiBqOwogICAgfQogIH0KICBjb3V0IDw8IGZpeGVkIDw8IHNldHByZWNpc2lvbigzKSA8PCBhbnMgPDwgJ1xuJzsKICBjZXJyIDw8ICJUaW1lOiAiIDw8IGRvdWJsZShjbG9jaygpKSAvIENMT0NLU19QRVJfU0VDIDw8ICdcbic7CiAgcmV0dXJuIDA7Cn0K