解這題,有幾種作法:
方法一:
1. 除數從 2 開始,若此被除數可以被除數 2 整除,就被除數就一直除以 2;若不行除數換用 3。
2. 一直重複到 除數的平方大於或小於 被除數。
方法二:
1. 求出小於此被除數開根號後的所有質數。
2. 在用這些質數去除被除數算出每個質因數出現的次數。
但底下程式碼是先建立質數表,再進行因數分解。
程式碼:
程式設計可以改變您的未來(Programming can change your future)。 雲林SONG 全名為雲林軟體工程(SOftware eNGineering),目標致力於軟體人才的培養並推廣開源軟體落實於資訊教育。程式設計的觀念是軟體產品的基礎,程式碼就像沙子一樣,要紮實,所建立出來的高塔才會穩固。本站也提供資訊教育相關的教學資源。 YunlinSONG stands for Yunlin SOftware eNGineering, offering tutorial for computer programming and promoting open-source software. Teaching resources in information technology education are provided here.
#include <iostream>
#include <sstream>
using namespace std;
int main()
{
string str;
while(getline(cin, str))
{
int serial;
char dummy;
double real;
double result = 0;
istringstream buffer(str);
while(buffer >> serial >> dummy >> real)
{
//cout << serial << dummy << real << " ";
if( serial & 1 )
result += real;
else
result -= real;
//cout << result << endl;
}
cout << result << endl;
}
return 0;
}
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
using namespace std;
int main(){
string input;
while( getline(cin, input) )
{
stack<int> value;
stringstream strStream(input);
string token;
int inStack;
int outStack;
while( strStream >> token )
{
switch(token[0])
{
case '+':
outStack = value.top();
value.pop();
inStack = value.top();
value.pop();
inStack += outStack;
value.push(inStack);
break;
case '-':
outStack = value.top();
value.pop();
inStack = value.top();
value.pop();
inStack -= outStack;
value.push(inStack);
break;
case '*':
outStack = value.top();
value.pop();
inStack = value.top();
value.pop();
inStack *= outStack;
value.push(inStack);
break;
case '/':
outStack = value.top();
value.pop();
inStack = value.top();
value.pop();
inStack /= outStack;
value.push(inStack);
break;
case '%':
outStack = value.top();
value.pop();
inStack = value.top();
value.pop();
inStack %= outStack;
value.push(inStack);
break;
default:
inStack = atol(token.c_str());
value.push(inStack);
break;
}
}
inStack = value.top();
cout << inStack << endl;
}
return 0;
}
#include <iostream>
#include <cmath>
using namespace std;
void prtMsg(const int &s, const int &n)
{
if( s == n )
cout << "完全數";
else if( s > n )
cout << "盈數";
else
cout << "虧數";
cout << endl;
}
int main()
{
int n;
while( cin >> n )
{
int s = 0;
for( int i = 1; i <= n/2; i++ )
{
if( n % i == 0 )
s += i;
}
prtMsg(s, n);
}
return 0;
}
sudo ./scull_load
sudo cp main.c /dev/scull0
cat /dev/scull0 | head -20 | tail -10
sudo ./scull_unload