BZOJ 1041 圆上的整点 数学

题目链接:

https://www.lydsy.com/JudgeOnline/problem.php?id=1041

题目大意:
求一个给定的圆(x^2+y^2=r^2),在圆周上有多少个点的坐标是整数。

思路:

看视频:

思路:
对于半径的平方进行质因数分解为p1q1p2q2...pnqn,ans = 4 * ∏(q1+1)(对于所有的pi满足模3为1)
由于这里给的半径是整数,直接对半径进行质因数分解,半径的平方只需在每个指数上乘以2即可。
 1 #include<bits/stdc++.h>
 2 #define IOS ios::sync_with_stdio(false);//不可再使用scanf printf
 3 #define Max(a, b) ((a) > (b) ? (a) : (b))//禁用于函数,会超时
 4 #define Min(a, b) ((a) < (b) ? (a) : (b))
 5 #define Mem(a) memset(a, 0, sizeof(a))
 6 #define Dis(x, y, x1, y1) ((x - x1) * (x - x1) + (y - y1) * (y - y1))
 7 #define MID(l, r) ((l) + ((r) - (l)) / 2)
 8 #define lson ((o)<<1)
 9 #define rson ((o)<<1|1)
10 #define Accepted 0
11 #pragma comment(linker, "/STACK:102400000,102400000")//栈外挂
12 using namespace std;
13 inline int read()
14 {
15     int x=0,f=1;char ch=getchar();
16     while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}
17     while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
18     return x*f;
19 }
20 
21 typedef long long ll;
22 const int maxn = 100 + 10;
23 const int MOD = 1000000007;//const引用更快,宏定义也更快
24 const int INF = 1e9 + 7;
25 const double eps = 1e-6;
26 
27 int main()
28 {
29     ll n;
30     cin >> n;
31     while(n % 2 == 0)n /= 2;
32     ll ans = 1;
33     for(ll i = 3; i <= n; i += 2)
34     {
35         if(i % 4 == 3)
36         {
37             while(n % i == 0)n /= i;
38             continue;
39         }
40         if(n % i == 0)
41         {
42             ll tmp = 0;
43             while(n % i == 0)tmp++, n /= i;
44             ans *= (tmp * 2 + 1);
45         }
46     }
47     if(n % 4 == 1 && n > 1)ans *= 3;
48     ans *= 4;
49     cout<<ans<<endl;
50     return Accepted;
51 }

 

 

转载于:https://www.cnblogs.com/fzl194/p/9684067.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值