题目描述

小象同学在初等教育时期遇到了一个复杂的数学题,题目是这样的:

给定自然数 nn,确定关于 x, y, zx,y,z 的不定方程 \displaystyle \sqrt{x - \sqrt{n}} + \sqrt{y} - \sqrt{z} =0x−n​​+y​−z​=0 的所有自然数解。

当时的小象同学并不会做这道题。多年后,经过高等教育的洗礼,小象同学发现这道题其实很简单。小象同学认为你一定也会做这道题,所以把这道题留给了你。为了便于输出,你不需要输出每一组解 (x, y, z)(x,y,z),你只需要给出解的数量和所有解的 x y zxyz 之和对 (10^9+7)(109+7) 取模的值即可。注意,解的数量不对 (10^9+7)(109+7) 取模。

 
 

输入描述

输入包含多组测试数据。输入的第一行包含一个正整数 TT (1 \leq T \leq10^41≤T≤104),表示测试数据的组数。接下来依次描述每组测试数据,对于每组测试数据:

仅一行,包含一个非负整数 nn (0 \leq n \leq 2 \times 10^90≤n≤2×109),含义如题面所示。

输出描述

对于每组数据,输出一行。若方程有无穷多组自然数解,则在这一行输出 \text{``infty''}“infty”(不含引号),否则在这一行输出两个整数,其中第一个整数表示方程的解数,第二个整数表示所有解的 x y zxyz 之和对 (10^9+7)(109+7) 取模的值,这两个整数之间用恰好一个空格隔开,行末不要有多余的空格。

样例输入 1

3
6
12
24

样例输出 1

0 0
1 12
2 72

提示

当 n = 12n=12 时,方程唯一的解为 x = 4x=4, y = 1y=1, z = 3z=3。

当 n = 24n=24 时,方程的两组解为 x = 5x=5, y = 2y=2, z = 3z=3 和 x = 7x=7, y = 1y=1, z = 6z=6。

思路:

移项,sqrt( x- sqrt(n) ) = sqrt(z)-sqrt(y)

两边平方(因为来说让求的就是自然数解,所以平方不会影响结果,。)

x-sqrt(n) =  z+y- 2*sqrt( z*y)

移项:

x-(z+y) = sqrt(n)-sqrt(4*z*y)

我们来分类讨论一波,

当n是一个平方数,

即 sqrt(n)是一个有理数,设m = sqrt(n)

那么我们令y或z任意一个为0,得如下(比如y=0)

x-z= m

显然上表达式是一个无穷解的不定方程。

可以得出结论,当n是一个平方数,那么有无穷解。

我们再来看 sqrt n 是一个无理数的时候,

想让方程成立,必须要满足 下面的两个条件

n=4*y*z

x=z+y

那么我们就可以直接枚举n/4的因子来得出我们的答案。

细节见代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define rt return
#define dll(x) scanf("%I64d",&x)
#define xll(x) printf("%I64d\n",x)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=;while(b){if(b%)ans=ans*a%MOD;a=a*a%MOD;b/=;}return ans;}
inline void getInt(int* p);
const int maxn=;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
const ll mod=1e9+;
int main()
{
//freopen("D:\\common_text\\code_stream\\in.txt","r",stdin);
//freopen("D:\\common_text\\code_stream\\out.txt","w",stdout);
int t;
gbtb;
cin>>t;
while(t--)
{
int n;
cin>>n;
int k=sqrt(n);
if(k*k==n)
{
cout<<"infty"<<endl;
}else
{
int cnt=;
ll ans=0ll;
if((n%)==)
{
n/=;
int x,y,z;
int m=sqrt(n);
for(int i=;i<=m;i++)
{
if((n%i)==)
{
y=i;
z=n/i;
x=y+z;
ans+=1ll*x*y*z;
ans%=mod;
cnt++;
}
}
cout<<cnt<<" "<<ans<<endl;
}else
{
cout<<"0 0"<<endl;
}
}
} return ;
} inline void getInt(int* p) {
char ch;
do {
ch = getchar();
} while (ch == ' ' || ch == '\n');
if (ch == '-') {
*p = -(getchar() - '');
while ((ch = getchar()) >= '' && ch <= '') {
*p = *p * - ch + '';
}
}
else {
*p = ch - '';
while ((ch = getchar()) >= '' && ch <= '') {
*p = *p * + ch - '';
}
}
}

最新文章

  1. Jexus Web Server 完全傻瓜化图文配置教程(基于Ubuntu 12.04.3 64位)[内含Hyper-v 2012虚拟机镜像下载地址]
  2. axis2+struts拦截地址冲突问题
  3. js模拟抛出球运动
  4. curl 模拟请求get/post
  5. MATLAB函数freqz()
  6. Effective C++ -----条款20:宁以pass-by-reference-to-const替换pass-by-value Prefer pass-by-reference-to-const to pass-by-value
  7. CSS抗锯齿 font-smoothing 属性介绍
  8. ELK笔记
  9. 导航VC的左右item代码
  10. postfix删除队列中的邮件
  11. JS改变input的value值不触发onchange事件解决方案 (转)
  12. matlab添加M_map工具箱(转 http://blog.sina.com.cn/s/blog_491b86bf0100srt9.html)
  13. js判断对象还是数组
  14. C语言的格式符
  15. redis入门(06)各种类型的操作命令
  16. 30岁天才上班族利用Python人脸监控BOSS,伪装成认真上班的样子!
  17. RPC-dubbo基本使用
  18. bochs的bochsrc说明
  19. wc语法
  20. 【LeetCode】13. 罗马数字转整数

热门文章

  1. Found duplicate classes/resources
  2. C/C++题库
  3. 屏蔽ffmpeg命令的所有提示
  4. C语言的AES加密
  5. spring 中的一些注解功能--不定更新
  6. GTX 1060 3GB 能否使用DeepFaceLab ?
  7. leetcode 125 验证回文字符串 Valid Palindrome
  8. spring boot加载自定义配置
  9. 系统分析与设计HW2
  10. kafka学习(七)