Hackerland is a happy democratic country with m×n cities, arranged in a rectangular m by n grid and connected by m roads in the east-west direction and n roads in the north-south direction. By public demand, this orthogonal road system is to be supplemented by a system of highways in sucha way that there will be a direct connection between any pair of cities. Each highway is a straight line going through two or more cities. If two cities lie on the same highway, then they are directly connected.If two cities are in the same row or column, then they are already connected by the existing orthogonal road system (each east-west road connects all the m cities in that row and each north-south road connects all the n cities in that column), thus no new highway is needed to connect them. Your task is to count the number of highway that has to be built (a highway that goes through several cities on a straight line is counted as a single highway).

Input
The input contains several blocks of test cases. Each test case consists of a single line containing two integers
1n,
m
300, specifying the number of cities. The input is terminated by a test case with
n = m = 0.
Output
For each test case, output one line containing a single integer, the number of highways that must be built.
Sample Input
2 4 3 3 0 0
Sample Output
12 14
N*M的点中除了水平和竖直的线有多少条。
设左上角为(1,1),先算出每个点到它左上方有多少个向量连到一个点不经过其它点,也就转化成1-i,1-j有多少个互质对数。还有一个问题就是可能从(i,j)往左上角的向量的终点,那个终点也可以以同样的向量作为起点,这条线就已经算过了,比如(3,3)到(2,2)有一条,但是和(2,2)到(1,1)是同一条。这种情况就要减去,可以发现(i/2,j/2)这个点出发的向量,在(i,j)出发的这些向量上对应的直线都已经计算过,所以要减去。最后要乘以2是因为直线朝右上方向跟朝左上方向是完全对称的。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<cstdlib>
#include<cmath>
#define INF 0x3f3f3f3f
#define MAXN 310
#define MAXM 20010
#define MAXNODE 4*MAXN
#define MOD 1000000000
#define eps 1e-9
using namespace std;
int N,M;
long long cnt[MAXN][MAXN],sum[MAXN][MAXN];
int gcd(int a,int b){
return a%b?gcd(b,a%b):b;
}
void init(){
memset(cnt,0,sizeof(cnt));
memset(sum,0,sizeof(sum));
for(int i=1;i<MAXN;i++)
for(int j=1;j<MAXN;j++) cnt[i][j]=cnt[i-1][j]+cnt[i][j-1]-cnt[i-1][j-1]+(gcd(i,j)==1?1:0);
for(int i=1;i<MAXN;i++)
for(int j=1;j<MAXN;j++) sum[i][j]=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+cnt[i][j]-cnt[i/2][j/2];
}
int main(){
//freopen("in.txt", "r", stdin);
init();
while(scanf("%d%d",&N,&M),N||M){
printf("%lld\n",2*sum[N-1][M-1]);
}
return 0;
}