文章

15

粉丝

0

获赞

8

访问

1.7k

头像
幂次分解 题解:
P5306 北京航空航天大学2025年机试题
发布于2026年3月20日 15:02
阅读数 179

#include<iostream>
#include<cmath>
using namespace std;

int main(){
    long long int n;
    cin >> n;
    if(n == 1){
        cout << 1;//判断特殊情况直接输出
        return 0;
    }
    
    long long int temp = n;
    bool first = true; //看看是不是第一个式子
    
    int count = 0;

//先把2这个搞了
    while(temp % 2 == 0){
        count++;
        temp /= 2;
    }
    if(count == 1){
        cout << "2";
        first = false;
    } else if(count > 1){
        cout << "2^" << count;
        first = false;
    }
    //为什么可以直接这样,因为如果3除完了,9也除不了,循环会直接过掉,步长为2是因为除了2,3,没有相邻的素数了捏
    for(long ...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发