1. 程式人生 > >hdu-2683 TCE-frep number system---完全數+二項展開式

hdu-2683 TCE-frep number system---完全數+二項展開式

mes PE () 判斷 pro pid href -- 標準

題目鏈接:

http://acm.hdu.edu.cn/showproblem.php?pid=2683

題目大意:

g(n)是n的因子和

技術分享圖片

兩種操作:

A a b 查詢a b區間有多少個n滿足上式。

Q a 查詢a滿不滿足上式

解題思路:

上述右邊二項式展開,就得到:

技術分享圖片

和上式對照,發現g(n) = 2n,由於g(n)是n的因子和,所以可以小於n的因子和就等於n

這就是完全數

而在2^63-1範圍內只有8個完全數,直接打表即可

坑:給的區間不是標準的左端點 右端點形式給的,也就是A a b中a可能大於b,需要判斷

#include<iostream>
#include<cstdio>
#include
<cmath> using namespace std; typedef long long ll; ll a[] ={6LL,28LL,496LL,8128LL,33550336LL,8589869056LL,137438691328LL,2305843008139952128LL}; int main() { char s[10]; while(cin >> s) { if(s[0] == A) { ll x, y; cin >> x >> y;
if(x > y)swap(x, y);//坑在這裏 ll ans = 0; for(int i = 0; i < 8; i++) if(a[i] >= x && a[i] <= y)ans++; cout<<ans<<endl; } else if(s[0] == Q) { ll x; cin >> x; ll flag
= 0; for(int i = 0; i < 8; i++) if(a[i] == x)flag = 1; cout<<flag<<endl; } } return 0; }

hdu-2683 TCE-frep number system---完全數+二項展開式