1. 程式人生 > >LightOJ 1341 Aladdin and the Flying Carpet(算術基本定理)

LightOJ 1341 Aladdin and the Flying Carpet(算術基本定理)

LightOJ 1341 Aladdin and the Flying Carpet

題意:

輸入一個矩形面積,以及矩形邊長的最小值,已知矩形不是正方形,求有多少種邊長組合。

思路:

轉化一下就是求面積的所有正約數個數的一半,然後去掉有邊長短於最小值以及正方形的情況就是最後答案。
至於求約數個數,由算術基本定理可知:

n=pa11pa22...pakk,=(a1+1)(a2+1)...(ak+1).

程式碼:

/*
* @author FreeWifi_novicer
* language : C++/C
*/
#include<cstdio>
#include<iostream> #include<cstring> #include<cstdlib> #include<cmath> #include<algorithm> #include<string> #include<map> #include<set> #include<vector> #include<queue> using namespace std; #define clr( x , y ) memset(x,y,sizeof(x)) #define cls( x ) memset(x,0,sizeof(x))
#define pr( x ) cout << #x << " = " << x << endl #define pri( x ) cout << #x << " = " << x << " " #define test( t ) int t ; cin >> t ; int kase = 1 ; while( t-- ) #define mp make_pair #define pb push_back typedef long long lint; typedef long long
ll; typedef long long LL; const int maxn = 1e6 + 47; bool noprime[maxn + 5] ; vector<int>p ; int sieve(){ cls( noprime ) ; p.clear(); for( int i = 2 ; i*i <= maxn ; i++ ) if( !noprime[i] ) for( int j = i * i ; j <= maxn ; j += i ) noprime[j] = true ; for( int i = 2 ; i <= maxn ; i++ ) if( !noprime[i] ) p.pb( i ) ; return p.size() ; } int calc( lint n , lint B , int len ){ lint res = 1 , tmp = n ; int i = 0 ; while( p[i] * p[i] <= n && i < len ) { lint cnt = 0 ; if( n % p[i] == 0 ){ while( n % p[i] == 0 ){ n /= p[i] ; cnt++ ; } } res *= cnt + 1 ; i++ ; } if( n > 1 ){ res <<= 1 ; } res >>= 1 ; n = tmp ; for( int i = 1 ; i < B ; i++ ) if( n % i == 0 ) res-- ; return res ; } int main(){ int len = sieve() ; test( t ){ lint a , b ; scanf( "%lld%lld" , &a , &b ) ; lint ans ; if( b * b >= a ){ ans = 0 ; } else ans = calc( a , b , len ) ; printf( "Case %d: %lld\n" , kase++ , ans ) ; } return 0; }

相關推薦

LightOJ 1341 Aladdin and the Flying Carpet算術基本定理

LightOJ 1341 Aladdin and the Flying Carpet 題意: 輸入一個矩形面積,以及矩形邊長的最小值,已知矩形不是正方形,求有多少種邊長組合。 思路

LightOJ 1341 Aladdin and the Flying Carpet唯一分解定理

void 都是 scanf esp for space tar sqrt lld http://lightoj.com/volume_showproblem.php?problem=1341 題意:給你矩形的面積(矩形的邊長都是正整數),讓你求最小的邊大於等於b的矩形的個

LIghtOJ-1341-Aladdin and the Flying Carpet 唯一分解定理

原題連結: It’s said that Aladdin had to solve seven mysteries before getting the Magical Lamp which summons a powerful Genie. Here we are concerned

Aladdin and the Flying Carpet算術基本定理

It's said that Aladdin had to solve seven mysteries before getting the Magical Lamp which summons a powerful Genie. Here we are concerned about the first

Light oj 1341 Aladdin and the Flying Carpet 唯一分解定理

It's said that Aladdin had to solve seven mysteries before getting the Magical Lamp which summons a powerful Genie. Here we are concerned about the fi

LightOJ 1341(Aladdin and the Flying Carpet )算術基本定理

star rect out post number text ask OS 約數 It‘s said that Aladdin had to solve seven mysteries before getting the Magical Lamp which summon

LightOJ-1341 Aladdin and the Flying Carpet 因子個數

這道題要用到一個結論: 設 N=p1^a1*p2^a2*p3^a3*...*pn^an(其中p1,p2,...,pn為N的因子,a1,a2,... ,an分別為因子的指數)(唯一分解定理);則 N的因子個數 M=(1 + a1)*(1 + a2)*(1 + a3)*..

[LightOJ 1341] Aladdin and the Flying Carpet (算數基本定理(唯一分解定理))

題目 fly pro sca rime memset def bool tin 題目鏈接: https://vjudge.net/problem/LightOJ-1341 題目描述: 問有幾種邊長為整數的矩形面積等於a,且矩形的短邊不小於b 算數基本定理的知識點:https

Aladdin and the Flying Carpet LightOJ - 1341算數基本定理

題目連結:qaq   題意:找出符合的因子對數的個數   思路:知道算數基本定理後就簡單了(感覺和暴力的複雜度一樣啊QAQ。。難受)   附上程式碼: #include<cstdio> #include<cmath>

Aladdin and the Flying Carpet LightOJ 1341

題意:給一對數字 a,b ,a是一個長方形的面積,問有多少種整數的邊的組合可以組成面積為a的長方形,要求最短的邊不得小於b 思路:用到了唯一分解定理;主要利用公式: 一個整數n可以表示為若干素數乘積: n = p1^a1 * p2^a2…pm^am; 則 n 的正因數的個數可以表示為:

數論題集1-7 (唯一分解定理+約數個數求和+素篩)Aladdin and the Flying Carpet

It's said that Aladdin had to solve seven mysteries before getting the Magical Lamp which summons a powerful Genie. Here we are concerned

LightOJ-1336-Sigma Function 算術基本定理

原題連結: Sigma function is an interesting function in Number Theory. It is denoted by the Greek letter Sigma (σ). This function actually denotes th

LightOJ-1236- Pairs Forming LCM 算術基本定理

原題連結: Find the result of the following code: long long pairsFormLCM( int n ) { long long res = 0; for( int i = 1; i <= n; i++ ) for( int j

LightOJ 1236 Pairs Forming LCM算術基本定理

LightOJ 1236 Pairs Forming LCM 題意: long long pairsFormLCM( int n ) { long long res = 0;

hdu4479 數學題算術基本定理

題目大意 給定一個三元組\((x,y,z)\)的\(gcd\)和\(lcm\),求可能的三元組的數量是多少,其中三元組是的具有順序的 其中\(gcd\)和\(lcm\)都是32位整數範圍之內 由算術基本定理可以得知: 如果$k=gcd(m,n) \(則\) k_p=min(m_p,n_p)$ 如果\(

uva 10791 Minimum Sum LCM算術基本定理

大意:給出一個數字n,LCM(q1,q2,……,qk)=n,求解q1,a2……qk的最小和。 分析:剛開始讀錯題了(又讀錯T_T),是一系列的數字之和。 由算術基本定理,,同時,發現如果,是最小的,也就是說如果是由產生的,那麼積是最小的,同時是一定的。比如,得到: 那麼和

lightOj 1341Aladdin and the Flying Carpet 算數基本定理

It's said that Aladdin had to solve seven mysteries before getting the Magical Lamp which summons a powerful Genie. Here we are concerned about the first

【light 1341Aladdin and the Flying Carpet

給你矩形的面積(矩形的邊長都是正整數),讓你求最小的邊大於等於b的矩形的個數。 肯定是和麵積的因子有關係了,邊長都是面積值的 因子。 那麼就可以算出面積值得所有因子,因為是讓求得矩形得個數,當然是要<<1了, 還有個限制條件就是最小得邊長要大於等於b得, 那麼把小於b得因子減去,

Ignatius and the Princess III杭電1028母函數

mission des panel mes content nat strong pro accepted Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others) Memory L

HDU 1029 Ignatius and the Princess IV map的使用

left pass http sample ace nta say limit har 傳送門: http://acm.hdu.edu.cn/showproblem.php?pid=1029 Ignatius and the Princess IV Time Limit: