decPlace_volume = floor(volume+.05) - ceil(volume); //should output -1, 0, or 1
decPlace_volume = pow(decPlace_volume,2); //should the above == -1, this should turn it into 1 while making 0 remain 0
基本上,我使用經典的分而治之,只要指數是偶數並提出這個問題。 int mymod(int a,int b){ //returns only positive value between 0 to b-1
return a%b<0 ? (a%b)+b : a%b;
}
int Solution::pow(int x, int n, int d) {
if(n==0) retu
我試圖找到一個給定的正整數Z,檢查如果Z可以寫爲:P Q,其中P和Q是正大於1的整數 若Z可以寫爲:P Q,返回1 ,否則返回0 我試過很多在線的解決方案, Check if one integer is an integer power of another Finding if a number is a power of 2 但它不是我需要的,任何提示或任何提示?