这个题其实很简单,但如果只是想用long long直接解决那是肯定不行的。
思路就是把底数分解成无数因子,在数出因子的个数,再遍历一遍,当因子种类和相应的个数都相同时,说明这两个数的结果也肯定相同。
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <stack>
#include <vector>
#include <set>
#include <queue>
#define M 100000 + 50
#define INF 10000000
#define pi acos(-1.0
using namespace std;
typedef long long LL;
LL m,n,a,b,cnt = 0;
int vis[105][105];
pair<map<LL,LL>,set<int> >tt[105][105];
pair<map<LL,LL>,set<int> >t2;
set<int>::iterator it;
void fun(int x,int y)
{
for(int i = 0; i < n; i++)
{
for(int j = 0; j < m; j++)
{
if(!vis[i][j])
if(tt[x][y].first == tt[i][j].first)
{
vis[i][j] = 1;
cnt --;
}
}
}
}
int main()
{
while(~scanf("%lld%lld%lld%lld",&m,&n,&a,&b))
{
memset(vis,0,sizeof(vis));
cnt = 0;
for (int i = 0; i < n; i++)
{
int k = i + a,l = 2;
while(k)
{
if(k % l == 0)
{
k = k / l;
t2.first[l] ++;
t2.second.insert(l);
}
else l ++;
if( k == 1)break;
}
for(int j = 0; j < m; j++)
{
for(it = t2.second.begin(); it != t2.second.end(); it ++)
{
tt[i][j].first[ *it ] = t2.first[ *it ] * (b + j);
tt[i][j].second = t2.second;
}
}
t2.first.clear();
t2.second.clear();
}
cnt = n * m;
for(int i = 0; i < n; i++)
{
for(int j = 0; j < m; j++)
{
if(!vis[i][j])
{
vis[i][j] = 1;
fun(i,j);
}
}
}
printf("%lld\n",cnt);
}
return 0;
}