c++欧拉函数按照这个图编,我写的是#include <iostream>#include <cmath>#include <iomanip>using namespace std;int main(){int m;int n;int p = 2;cout<< "请输入数值:" << endl;cin >> n;m
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/16 00:24:53
c++欧拉函数按照这个图编,我写的是#include <iostream>#include <cmath>#include <iomanip>using namespace std;int main(){int m;int n;int p = 2;cout<< "请输入数值:" << endl;cin >> n;m
c++欧拉函数
按照这个图编,我写的是
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main()
{
int m;
int n;
int p = 2;
cout<< "请输入数值:" << endl;
cin >> n;
m = n;
int k = 0;
if (p*p>n&&n>1)
{
cout << m << endl;
}
while (p*p <= n,k = 0)
{
while (n / p == 0)
{
n /= p; k++;
}
if (k >= 1)
{
m = m*(p - 1) / p;
}
p++;
}
if (n>1)
{
m = m*(n - 1) / n;
cout << m << endl;
}
return m;
cout << m << endl;
return 0;
}
,反正是不对的,求各位大神指教
c++欧拉函数按照这个图编,我写的是#include <iostream>#include <cmath>#include <iomanip>using namespace std;int main(){int m;int n;int p = 2;cout<< "请输入数值:" << endl;cin >> n;m
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main()
{
int m;
int n;
int p = 2;
cout<< "请输入数值:" << endl;
cin >> n;
m = n;
int k = 0;
/*
if (p*p>n&&n>1)
{cout << m << endl;
}*///放在后面写
while (p*p <= n)
//不能写成 p*p <= n,k=0,这样写是逗号表达式,表达式的值取最后一个表达式的值k=0,表达式恒假,导致循环一次也不做
{
k = 0
while (p / n != 0)//除号两边写反了,循环的条件是p/n不为0
{
n /= p; k++;
}
if (k >= 1)
{
m = m*(p - 1) / p;
}
p++;
}
if (n>1)
{
m = m*(n - 1) / n;
/*
cout << m << endl;*///放在后面写
}
//return m;
//图上是用函数做的,所以有返回,这里你直接写在主程序中,所以不要加return m
cout << m << endl;//输出m的值
return 0;
}
有什么问题再联系