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;
    }
  • 相关阅读:
    JVM系列四:生产环境参数实例及分析【生产环境实例增加中】
    JVM系列三:JVM参数设置、分析
    JVM系列二:GC策略&内存申请、对象衰老
    JVM系列一:JVM内存组成及分配
    windows下揪出java程序占用cpu很高的线程 并找到问题代码 死循环线程代码
    微信小程序使用字体图标
    Jetson tx2 串口通信
    categorical[np.arange(n), y] = 1 IndexError: index 2 is out of bounds for axis 1 with size 2
    cannot import name '_imaging' 报错
    VS2015 opencv 无法打开文件“opencv_calib3d330d.lib”
  • 原文地址:https://www.cnblogs.com/Staceyacm/p/11241292.html
Copyright © 2011-2022 走看看