Six

Description

Diophantus of Alexandria was an egypt mathematician living in Alexandria. He was one of the first mathematicians to study equations where variables were restricted to integral values. In honor of him, these equations are commonly called diophantine equations. One of the most famous diophantine equation is x^n + y^n = z^n. Fermat suggested that for n > 2, there are no solutions with positive integral values for x, y and z. A proof of this theorem (called Fermat's last theorem) was found only recently by Andrew Wiles. 

Consider the following diophantine equation: 

1 / x + 1 / y = 1 / n where x, y, n ∈ N+ (1)


Diophantus is interested in the following question: for a given n, how many distinct solutions (i. e., solutions satisfying x ≤ y) does equation (1) have? For example, for n = 4, there are exactly three distinct solutions: 

1 / 5 + 1 / 20 = 1 / 4 
1 / 6 + 1 / 12 = 1 / 4 
1 / 8 + 1 / 8 = 1 / 4



Clearly, enumerating these solutions can become tedious for bigger values of n. Can you help Diophantus compute the number of distinct solutions for big values of n quickly? 
 

Input

The first line contains the number of scenarios. Each scenario consists of one line containing a single number n (1 ≤ n ≤ 10^9). 
 

Output

The output for every scenario begins with a line containing "Scenario #i:", where i is the number of the scenario starting at 1. Next, print a single line with the number of distinct solutions of equation (1) for the given value of n. Terminate each scenario with a blank line. 
 

Sample Input

 
    
2 4 1260
 

Sample Output

 
    
Scenario #1: 3 Scenario #2: 113
 

数论题,主要是推公式!!!!

1/x+1/y = 1/n 设y = n + k;
==>1/x + 1/(n+k)=1/n;
==>x = n^2/k + n;
因为x为整数,k就是n^2的约数。然后对其素因子分解就可以了。


接下来还有个知识点是:
如果X  = p1^a1 * p2^a2 * p3^a3*…*pn^an,那么
1、X的约数的个数为(a1+1)*(a2+1)*…*(an+1);
2、X的约束的和为
(p1^0+p1^1^…+p1^a1)*…* (pn^0+pn^1^…+pn^an)。
虽然这题只用到了第一个知识点。。。。


#include <iostream>
#include<memory.h>
using namespace std;
bool p[100000];
int su[100000],k=0;
void get()
{
    memset(p,1,sizeof(p));
    for(long long i=2;i<100000;i++)
    {
        if(p[i]==1)
        {
            su[k++]=i;
           // if(k==1||k==2||k==3)cout<<su[0]<<endl;
            for(long long j=i*i;j<100000;j+=i)
            p[j]=0;
        }
    }
   // cout<<su[0]<<endl;
}
int get1(int m)
{
    int x=0,s=1,num=0;
    for(int i=0;su[i]*su[i]<=m&&i<k;i++)
    {
        num=0;
        if(m%su[i]==0)
        {
           // cout<<su[i]<<endl;
            while(m%su[i]==0)
            num++,m/=su[i];
            s*=(2*num+1);
            x++;
        }
    }
    if(m>1)num=1,s*=(2*num+1);
    return s;
}
int main()
{
    get();
    //for(int i=0;i<100;i++)
   // cout<<su[i]<<' ';
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        int m;
        cin>>m;
        int o=get1(m);
        cout<<"Scenario #"<<i+1<<":"<<endl<<(o+1)/2<<endl<<endl;
    }
    return 0;
}


转载于:https://www.cnblogs.com/martinue/p/5490556.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值