zoukankan      html  css  js  c++  java
  • 5J.炫酷数学(C++)

    炫酷数学(C++)

    点击做题网站链接

    题目描述
    小希最近想知道一个东西,就是A+B=A|B(其中|为按位或)的二元组有多少个。
    当然,直接做这个式子对小希来说太难了,所以小希改变了一些条件,她仅想知道其中A,B<N的情况,其中N为2的幂次。
    当然,(A=1,B=0)和(A=0,B=1)被认为是不同的二元组。

    输入描述:
    第一行输入一个非负整数M。
    N=2M,M100N=2^M,M≤100
    即2的M次为N。

    输出描述:
    一个整数ans,对998244353取模。

    示例1
    输入

    0

    输出
    1

    示例2
    输入

    71

    输出
    588378066

    题目思路:

    几乎是一道纯数学题。
    考虑每一位,只有在(0,0)(0,1)(1,0)的三种情况时满足条件。
    根据乘法原理,答案即为3^M

    解题代码1:

    #include <iostream>
    using namespace std;
    const int mod = 998244353;
     
    int main()
    {
    	ios::sync_with_stdio(false);//加速
        int M;
        long long ans = 1;
        cin >> M;
        for(int i=0;i<M;++i)
        {
            ans *= 3;
            ans %= mod;
        }
        cout << ans << endl;
    }
    

    解题代码2:

    #include <iostream>
    using namespace std;
    const int mod = 998244353;
    
    long long M,ans[105];
     
    int main()
    {
        ios::sync_with_stdio(false);//加速
        cin >> M;
        ans[0] = 1;
        for (int i=1;i<=100;++i) ans[i] = ans[i-1]*3%mod;
        cout << ans[M] << endl;
    }
    
  • 相关阅读:
    java Set(集合)
    java Stack(栈)
    java LinkedList(链表)
    简单的maven配置
    Linux下如何查找.sh后缀的文件
    linux 下shell中if的“-e,-d,-f”是什么意思
    linux重定向
    shell中$0,$?,$!等的特殊用法
    向shell脚本中传入参数
    mysql索引
  • 原文地址:https://www.cnblogs.com/yuzilan/p/10626094.html
Copyright © 2011-2022 走看看