• Comet_oj_#0_A


     这道题通过简化方程可得,当n为平方数的时候,解为无穷,当%4不为0时为0 0;计算

    但是要小心,这道题的代码要经过优化。一下为两种代码,一个tle,一个accept。

    #include<iostream>
    #include<cmath>
    using namespace std;
    typedef long long ll;
    const ll mod=1e9+7;
    int main()
    {
        int t;
        ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
        cin>>t;
        while(t--)
        {
            ll n;
            cin>>n;
            double k=sqrt(n);
            if(k==(int)k)
            {
                cout<<"infty"<<endl;
              continue;
            }
              if(n%4!=0){
                cout<<0<<" "<<0<<endl;
              continue;
            }else
            {
                int cnt=0;
                ll ans=0ll;
                    n/=4;
                    int m=sqrt(n);
                    for(ll i=1;i<=m;i++)
                    {
                        if((n%i)==0)
                        {
                            ans+=n*(i+n/i);
                            ans%=mod;
                            cnt++;
                        }
                    }
                    cout<<cnt<<" "<<ans<<endl;
            }
        }
        return 0;
    }
    tle
    #include<iostream>
    #include<cmath>
    using namespace std;
    typedef long long ll;
    const ll mod=1e9+7;
    int main()
    {
        //freopen("D:\\common_text\\code_stream\\in.txt","r",stdin);
        //freopen("D:\\common_text\\code_stream\\out.txt","w",stdout);
        int t;
        ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
        cin>>t;
        while(t--)
        {
            int n;
            cin>>n;
            double k=sqrt(n);
            if(k==(int)k)
            {
                cout<<"infty"<<endl;
              continue;
            }
              if(n%4!=0){
                cout<<0<<" "<<0<<endl;
              continue;
            }else
            {
                int cnt=0;
                ll ans=0ll;
                    n/=4;
                    int x,y,z;
                    int m=sqrt(n);
                    for(int i=1;i<=m;i++)
                    {
                        if((n%i)==0)
                        {
                            ans+=1ll*n*(i+n/i);
                            ans%=mod;
                            cnt++;
                        }
                    }
                    cout<<cnt<<" "<<ans<<endl;
            }
        }
        return 0;
    }
    accept

    以上告诉我们,要学会优化!

  • 相关阅读:
    ecshop ajax请求验证captcha(验证码)
    ecshop ajax内置函数Ajax.call
    Execl中函数使用总结
    php应用篇 PHPMailer使用
    Jquery中的选择器
    你的水桶有多满
    在纸上写todo list还是用APP?
    absolute居中
    搬家租房总结
    编译器的作用:将汇编语言翻译成机器语言
  • 原文地址:https://www.cnblogs.com/Ean1zhi/p/12215937.html
Copyright © 2020-2023  润新知