http://acm.xidian.edu.cn/problem.php?id=1031
简单找规律,a[i][j] = (i+j)/gcd(i,j)。
#include<iostream> #include<algorithm> #include<cstring> #include<cstdio> using namespace std; int n,m; int gcd(int a,int b) { return b?gcd(b,a%b):a; } int main() { while(~scanf("%d%d",&n,&m)) { int ans = 0; for(int i = 1;i <= n;i++) { for(int j = 1;j <= m;j++) { ans += (i+j)/gcd(i,j); } } printf("%d\n",ans); } return 0; }
时间: 2024-10-07 05:25:13