首页 > 代码库 > XDOJ_1031 _水

XDOJ_1031 _水

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;}

 

XDOJ_1031 _水