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;
    }
  • 相关阅读:
    字体下载大宝库:30款好看的免费英文字体
    jQuery Mapael – 呈现动态的矢量地图
    Qt:用 __thread 关键字让每个线程有自己的全局变量
    从C++到Qt(舍弃IDE或qmake、cmake等工具的束缚,尝试通过几个例子)
    C++11(及现代C++风格)和快速迭代式开发
    EventBus + Redis发布订阅模式
    并发、并行和高并发
    Span<T>和Memory<T>
    Lucene.Net做一个简单的搜索引擎-全文索引
    技术架构演变
  • 原文地址:https://www.cnblogs.com/Staceyacm/p/11241292.html
Copyright © 2011-2022 走看看