zoukankan      html  css  js  c++  java
  • P2508 [HAOI2008]圆上的整点

    P2508 [HAOI2008]圆上的整点

    题意

    求一个给定的同 (left(x^{2}+y^{2}=r^{2} ight),) 在圆周上有多少个点的坐标是整数。

    设正整数(n=2^{a_0}p_{1}^{a_1}dots p_{s}^{a_s}q_{1}^{b_1}dots q_{t}^{b_t}),其中(p_1,dots ,p_s,q_1,dots ,q_t)是不同的质数,(p_iequiv 1pmod{4}(1leq i leq s))(q_jequiv 3pmod{4}(1leq j leq t)),而(a_0,dots ,a_s,b_1,dots ,b_t)是非负整数,则当(b_1,dots ,b_t)至少有一个为奇数时,(f(n)=0)。而当(b_1,dots ,b_t)都是偶数时,(f(n)=4(a_1+1)(a_2+1)dots (a_s+1)),函数(f(n))表示方程(x^2+y^2=n)的整数解个数。(非负整数解个数是f(n)/4)

    上述定理中 (f(n)) 函数表示方程 (x^{2}+y^{2}=n) 的正整数解个数.于是我们可以运用此定理 ,将题目中的 (r) 分解质因数 ,由于是 (x^{2}+y^{2}=r^{2},) 所以 (b_{1} ldots b_{t}) 肯定都为偶数,直接将r的因数乘2后带入上述式子即可。

    #include <bits/stdc++.h>
    using namespace std;
    map<int,int>cnt;
    void get(int n){
        int temp=n;
        int srt=sqrt(n);
        int num=0;
        for(int i=2;i<=srt+1;i++){
            while(temp%i==0){
                temp/=i;
                cnt[i]++;
            }
        }
        if(temp>1){
            cnt[temp]++;
        }
    }
    int main () {
        int r;
        scanf("%d",&r);
        get(r);
        int ans=4;
        for(auto x:cnt){
            int p=x.first,a=x.second;
            a*=2;
            if(p%4==1){
                ans=ans*(a+1);
            }
        }
        printf("%d
    ",ans);
    }
    

    引用: https://www.luogu.com.cn/blog/Guess00/solution-P2508

  • 相关阅读:
    3.学习Dispatcher
    2学习Application
    学习WPF-1
    Content-Type说明
    AspNet Core定时任务
    Asp.Net Core跨域配置
    学习Emmet
    Asp.Net Core存储Cookie不成功
    服务端编码和解码
    C#7特性
  • 原文地址:https://www.cnblogs.com/ucprer/p/14566120.html
Copyright © 2011-2022 走看看