JZOJ5554 Polynomial

Polynomial

题目描述:
在这里插入图片描述

输入:
在这里插入图片描述

这道题有毒,一开始毫无思路。
然后瞅了瞅题解,发现很简单。

首先判掉几种特殊的情况:

  1. a = 1 a = 1 b = 1 b = 1 c = 1 c = 1 , 输出 i n f i n i t y infinity
  2. b = a b = a b ! = c b != c , 无解。
  3. 如果 a = 1 a = 1 ,且 c c b b 的幂次,输出 1 1
  4. 如果 a , b , c a,b,c 不满足单调性,无解。
  5. 如果 b = = 1 b == 1 ,如果 c = = 1 c == 1 输出 1 1 ,否则输出 0 0

然后很显然 b = = c b == c 时有常数的情况,答案先加一。
很显然仅有一个方程,系数为 c c b b 进制下的每一位。(显然因为 a , b , c a,b,c 均为正整数)

在判断一下这个方程是否满足 f ( a ) = b f(a)=b

#include <cstdio>
#include <cstring>
using namespace std;

typedef long long ll;

ll a,b,c,ans = 0,tot = 0,A = 1,top = 0, x[250];

int main()
{
	freopen("polynomial.in","r",stdin);
	freopen("polynomial.out","w",stdout);
	
	for(;~scanf("%lld%lld%lld",&a,&b,&c);top = 0,ans = 0,A = 1,tot = 0)
	{
		if(a == 1 && b == 1 && c == 1) { printf("infinity\n"); continue; }
		if(b == a && c != b) { printf("0\n"); continue; }
		ll t = c; if(a == 1) for(;t % b == 0;) t /= b;	
		if(t == 1 && a == 1) { printf("1\n"); continue;}
	
		if(a > b && b < c || a < b && b > c) { printf("0\n"); continue; }
		if(b == 1) { printf("%lld\n",b == c); continue; }
		if(b == c) ++ans; t = c;
		
		for(;t;t = t / b) x[++top] = t % b;
		for(int i = 1;i <= top; ++ i) tot += x[i] * A, A = A * a;
		if(tot == b) ++ans; printf("%lld\n",ans);
	}
	
	fclose(stdin); fclose(stdout);
	return 0;
}

这题不难写,但是数学不好真惨。

猜你喜欢

转载自blog.csdn.net/INnovate2030/article/details/103506936