日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

SDNU 1427.分解质因数(水题)

發布時間:2024/4/15 编程问答 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 SDNU 1427.分解质因数(水题) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Description

問題描述   求出區間[a,b]中所有整數的質因數分解。 輸入格式   輸入兩個整數a,b。 輸出格式   每行輸出一個數的分解,形如k=a1*a2*a3...(a1< =a2< =a3...,k也是從小到大的)(具體可看樣例) 樣例輸入 3? 10 樣例輸出 3=3 4=2*2 5=5 6=2*3 7=7 8=2*2*2 9=3*3 10=2*5 提示   先篩出所有素數,然后再分解。 數據規模和約定   2< =a< =b< =10000

Input

Output

Sample Input

Sample Output

思路:明明就是一道水題,debug卻讓我吐血!一開始我用vector來存數據,但是爆了,也不知道為什么會爆,我明明開了很大的數。后來只能用簡化的辦法了。 #include <cstdio> #include <iostream> #include <cmath> #include <string> #include <cstring> #include <algorithm> #include <queue> #include <vector> #include <map> using namespace std; #define ll long long const int inf = 0x3f3f3f3f; const int mod = 1e9+7;int a, b, tot, pri[10000+8], en[10000+8]; bool is[10000+8];void E() {tot = 0;memset(is, 1, sizeof(is));is[0] = is[1] = 0;for(int i = 2; i<10000+8; i++){if(is[i]){pri[tot++] = i;for(int j = i+i; j<10000+8; j += i)is[j] = 0;}} }int main() {E();while(~scanf("%d%d", &a, &b)){for(int i = a; i <= b; i++){int id = 0, buffer = i;for(int j = 0; j < tot && pri[j]*pri[j] <= i; j++){if(buffer%pri[j] == 0){while(buffer%pri[j] == 0){en[id++] = pri[j];buffer /= pri[j];}}}if(buffer>1)en[id++] = buffer;printf("%d=", i);bool flag = 0;for(int j = 0; j<id; j++){if(flag)printf("*");flag = 1;printf("%d", en[j]);}printf("\n");}}return 0; }

?

轉載于:https://www.cnblogs.com/RootVount/p/11252860.html

總結

以上是生活随笔為你收集整理的SDNU 1427.分解质因数(水题)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。