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;
    }
  • 相关阅读:
    洛谷 P2896 [USACO08FEB]Eating Together S
    洛谷 P1564 膜拜
    洛谷 P1684 考验
    洛谷 P2031 脑力达人之分割字串
    洛谷 P2725 邮票 Stamps
    洛谷 P2904 [USACO08MAR]跨河River Crossing
    洛谷 P1929 迷之阶梯
    洛谷 P2375 [NOI2014]动物园
    谷歌浏览器禁止表单自动填充
    SQL数据同步之发布订阅
  • 原文地址:https://www.cnblogs.com/Staceyacm/p/11241292.html
Copyright © 2011-2022 走看看