zoukankan      html  css  js  c++  java
  • Diophantus of Alexandria(唯一分解定理)

    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 xn + yn = zn. Fermat suggested that for n > 2, there are no solutions with positive integral values for xy 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)

    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:

    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 nquickly?

    Input

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

    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

    代码:
    #include<cstdio>
    #include<iostream>
    #include<cstring>
    #include<algorithm>
    #include<queue>
    #include<stack>
    #include<set>
    #include<vector>
    #include<map>
    #include<cmath>
    const int maxn=1e5+5;
    typedef long long ll;
    using namespace std;
    
    int prime[1000005];
    bool vis[1000005];
    int cnt =0;
    void erla() {
    
        memset(vis,false,sizeof(vis));
        memset(prime,0,sizeof(prime));
        for(int t=2; t<=1000003; t++) {
            if(!vis[t]) {
                prime[cnt++]=t;
            }
            for(int j=0; j<cnt&&t*prime[j]<=1000003; j++) {
                vis[t*prime[j]]=true;
                if(t%prime[j]==0) {
                    break;
                }
            }
        }
    }
    
    int main()
    {
       int T;
       erla();
       cin>>T;
       int ca=1;
       while(T--)
       {
        int n;
        scanf("%d",&n);
        ll ans=1;
        for(int t=0;t<cnt;t++)
        {
            ll s1=0;
            while(n%prime[t]==0)
            {
                n/=prime[t];
                s1++;
            }
            ans=ans*(2*s1+1);
            if(n==1)
            {
                break;
            }
        }
        if(n!=1)
        ans*=3;
        ans=(ans+1)/2;
        printf("Scenario #%d:
    ",ca++);
        printf("%lld
    
    ",ans);
       }
       return 0;
    }
  • 相关阅读:
    iOS中过滤html文档中的标签
    十六进制函数转换UIColor对象
    vue使用echarts
    vue打包部署
    charels代理跨域访问接口
    vue 使用highcharts
    vue配置跨域
    命令行
    安装nvm
    vsCode个人设置
  • 原文地址:https://www.cnblogs.com/Staceyacm/p/11241292.html
Copyright © 2011-2022 走看看