TCE-frep number system hdu-2683 (完全数+二项展开式)

TCE-frep number system

Number theory is one of the oldest branches of pure mathematics, and one of the largest. Of course, it concerns questions about numbers, usually meaning whole numbers or rational numbers (fractions).
Elementary number theory involves divisibility among integers -- the division "algorithm", the Euclidean algorithm (and thus the existence of greatest common divisors), elementary properties of primes (the unique factorization theorem, the infinitude of primes), congruences, including Fermat's little theorem and Euler's theorem extending it. But the term "elementary" is usually used in this setting only to mean that no advanced tools from other areas are used -- not that the results themselves are simple.
Topics in elementary number theory -- the solutions of sets of linear congruence equations (the Chinese Remainder Theorem), or solutions of single binary quadratic equations (Pell's equations and continued fractions), or the generation of Fibonacci numbers or Pythagorean triples -- turn out in retrospect to be harbingers of sophisticated tools and themes in other areas. The remaining parts of number theory are more or less closely allied with other branches of mathematics, and typically use tools from those areas.
Also there lots of branches, such as Combinatorial Number Theory, Algebraic Number Theory, Analytic Number Theory, additive number theory, Geometric number theory, Transcendental number theory, etc.
Today give you a function g(n) whose value is the sum of all the divisors of n .
If n satisfies following rule:

这里写图片描述
We call n is a TCE-frep number,your task is easy,detail to input and output.
Input
Two ways of input:
A x y
(x, y <= 2^63-1)
Q n
(1 <= n <= 2^63-1)
Output
For A x y , output the number of TCE-frep number which located between x and y
For Q n , output “1” if n is a TCE-frep number else output “0”
Sample Input

A 5 70 
A 6 6
Q 6
Q 1

Sample Output

2
1
1
0
题意:

g(n)是n的因子和
这里写图片描述

两种操作:

A a b 查询a b区间有多少个n满足上式。

Q a 查询a满不满足上式

思路:

每当我们得到一个二项式的等式的时候,我们应该想到将他展开看看是什么样的,能否消去某些项

ni=0Cin(g(n)n)inni=(n+2)n=ni=0Cin2inni ∑ i = 0 n C n i ( g ( n ) n ) i n n − i = ( n + 2 ) n = ∑ i = 0 n C n i 2 i n n − i

我们发现可以消掉某些项,消去后得到

ni=0(g(n)n)i=ni=02i ∑ i = 0 n ( g ( n ) n ) i = ∑ i = 0 n 2 i

因此我们得到

g(n)n=2 g ( n ) n = 2

g(n)=2n g ( n ) = 2 n

因为g(n)代表n的因子和所以,n是

完全数


等等什么是完全数????

完全数定义:
完全数是等于其真因数之和的数

啥意思?

也就是说某个数n,出去它本身的因数之和等于n,这样的数叫完全数

那么很明显它的所有因数之和就是2n了

下面给出

欧几里得完全数公式:

如果 2p1 2 p − 1 是素数,则 2p1(2p1) 2 p − 1 ⋅ ( 2 p − 1 ) 是完全数

定理这里暂不给出证明

但是根据这个定理我们完全可以枚举p,然后判断 2p1 2 p − 1 是素数枚举出题目要求的 2631 2 63 − 1 范围内的所有完全数
枚举:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
typedef unsigned long long ll;
bool isprime[1000000];
bool judge(ll n){
    for(ll i = 2; i <= sqrt(n); i++){
        if(n % i == 0) return false;
    }
    return true;
}
ll q_pow(ll a, ll b){
    ll ans = 1;
    while(b){
        if(b & 1) 
            ans = ans * a;
        b >>= 1;
        a = a * a;
    }
    return ans;
} 
int main(){
    for(int i = 2; i < 40; i++){
        ll a = q_pow(2,i) - 1;
        if(judge(a)){
            cout << a * q_pow(2,i-1) << endl;
        }
    }
    return 0;
}

结果:
6
28
496
8128
33550336
8589869056
137438691328
2305843008139952128

发现题目要求的范围内的完全数只有8个

这之后就成了暴力。。

注意题目所给的xy不一定都是x < y,需要进行判断

题解

code:

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long ll;
ll a[] = {6LL,28LL,496LL,8128LL,33550336LL,8589869056LL,137438691328LL,2305843008139952128LL};
int main(){
    char s[10];
    while(~scanf("%s",s)){
        if(s[0] == 'A'){
            ll x,y;
            scanf("%lld%lld",&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++;
            }
            printf("%lld\n",ans);
        }
        else if(s[0] == 'Q'){
            ll x;
            scanf("%lld",&x);
            ll flag = 0;
            for(int i = 0; i < 8; i++){
                if(a[i] == x)
                    flag = 1;
            }
            printf("%lld\n",flag);
        }
    }
    return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值