• Comet OJ Contest #0 解方程(暴力)


    题意:

    给定自然数n,求满足$displaystyle sqrt{x-sqrt{n}}=sqrt{z}-sqrt{y}$的x,y,z,输出解的个数以及所有解 xyz的和

    n<=1e9,t<=5000,1500ms

    思路:

    $displaystyle x-sqrt{n}=z+y-2sqrt{yz}$
    $if sqrt{n}quad isquad rational quad number:$
    $qquad atquad leastegin{Bmatrix}
    x=sqrt{n}+z\
    y=0
    end{Bmatrix}$
    $else egin{Bmatrix}
    n = 4yz\
    x=y+z\
    x^2 geq n
    end{Bmatrix} quad infty$
    $whichquad is$
    $displaystyle
    egin{Bmatrix}
    yz = frac{n}{4}\
    (y+z) geq n
    end{Bmatrix}$

    #include<iostream>
    #include<cstdio>
    #include<algorithm>
    #include<cmath>
    #include<cstring>
    #include<string>
    #include<stack>
    #include<queue>
    #include<deque>
    #include<set>
    #include<vector>
    #include<map>
    #include<functional>
        
    #define fst first
    #define sc second
    #define pb push_back
    #define mem(a,b) memset(a,b,sizeof(a))
    #define lson l,mid,root<<1
    #define rson mid+1,r,root<<1|1
    #define lc root<<1
    #define rc root<<1|1
    #define lowbit(x) ((x)&(-x)) 
    
    using namespace std;
    
    typedef double db;
    typedef long double ldb;
    typedef long long ll;
    typedef unsigned long long ull;
    typedef pair<int,int> PI;
    typedef pair<ll,ll> PLL;
    
    const db eps = 1e-6;
    const int mod = 1e9+7;
    const int maxn = 2e6+100;
    const int maxm = 2e6+100;
    const int inf = 0x3f3f3f3f;
    const db pi = acos(-1.0);
    
    int main() {
        int t;
        scanf("%d", &t);
        while(t--){
            int n;
            scanf("%d", &n);
            if((int)sqrt(n)*sqrt(n)==n){
                printf("infty
    ");
            }
            else{
                if(n%4!=0){
                    printf("0 0
    ");
                }
                else{
                    int cnt = 0;
                    ll ans = 0;
                    int m = sqrt(n/4+0.5);
                    int c = sqrt(m);
                    for(int i = 1; i <= m; i++){
                        if((n/4)%i==0&&((i+(n/4)/i)>=c)){
    
                            ans += 1ll*i*(n/4)/i*(i+(n/4)/i);
                            cnt++;
                            ans%=mod;
                        }
                    }
                    printf("%d %lld
    ",cnt,ans);
                }
            }
        }
        return 0;
    }

    这题卡long long的。。

    代码:

  • 相关阅读:
    qml 无边框
    Qt 参考链接
    QPushButton QSS
    Head First设计模式之备忘录模式
    Head First设计模式之访问者模式
    Head First设计模式之状态模式
    web打印总结
    Head First设计模式之单例模式
    .Net IOC框架入门之一 Unity
    第五章 MVC之Bundle详解
  • 原文地址:https://www.cnblogs.com/wrjlinkkkkkk/p/10644502.html
Copyright © 2020-2023  润新知