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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

hdu2964-Prime Bases

發布時間:2025/3/15 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 hdu2964-Prime Bases 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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

題意,給你一個整數n,現在要你分解成 n = k1 * ( 2 * 3 * ....*x1 ) + k2 * ( 2 * 3 * .... *x2 ) + ........;其中后面均為素數,且是由最小的2遞增相乘;

分析:首先打印素數表;然后使用數組a【】來儲存到從第一個素數2到第幾個素數乘積。找到第i個小于n,第i +1個大于n的數值 i ;

然后分解n.使用數組b【】來儲存a【i】的個數;同理執行多次,知道將n分解完畢;

如下的這種輸出格式比較好,大家可以參考下;

參照做的;

?

#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<bitset> #include<iomanip>using namespace std; const int prime[]={2,3,5,7,11,13,17,19,23,29,31,37,39,41,43,47,51,53,57,59}; __int64 a[21]; int b[21],rem; void init( ) {a[ 0 ] = 1 ;for( int i =1 ; i < 21 ; ++i )a[ i ] = a[ i - 1 ] * prime[ i - 1 ] ; }void deal( int n ) {int i ;for( int i = 0 ; i < 21 ; ++i ){if( a[ i ] <= n && a[ i + 1 ] > n ){rem = i ;break ;}}memset( b , 0 ,sizeof( b ) ) ;for( int i = rem ; i >=0 ; --i ){b[ i ] = n / a[ i ] ;n %= a[ i ] ;} }void output( int n ) {cout << n << " = " ;for( int i = 0 ; i <= rem ; ++i ){if( b[ i ] ){cout << b[ i ] ;for( int j = 0 ; j < i ; ++j )cout << "*" << prime[ j ] ;if( i != rem )cout << " + " ;}}cout << endl ; }int main( ) {init( ) ;int n ;while( cin >> n , n ){deal( n ) ;output( n );}return 0 ; }


?

?

轉載于:https://www.cnblogs.com/dyllove98/p/3206309.html

總結

以上是生活随笔為你收集整理的hdu2964-Prime Bases的全部內容,希望文章能夠幫你解決所遇到的問題。

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