您的位置:首页 > 其它

hdu 5597(欧拉,找规律)

2015-12-12 22:57 375 查看
hdu 5597

打表f(x) = x + 1,找规律,欧拉函数

#include <iostream>   //打表找规律
#define LL long long
#include <cmath>

using namespace std;

LL c(int a, int b)
{
LL t = 1;

if (a > b - a)
{
a = b - a;
}

for (int i = 1; i <= a; i++)
{
t = t * (b - i + 1) / i;
}

return t;
}

int main()
{
for (int x = 1; x <= 10; x++)
{
double sum = 0;

for (int k = 0; k <= x; k++)
{
// cout << "c " << k << ' ' << 2 * x - k + 1 << ' ' << c(k, 2 * x - k + 1) << endl;
sum += pow(-1.0, k) * pow (2.0, 2 * x - 2 * k) * c(k, 2 * x - k + 1) ;
}

printf("%d %lld\n", x, (LL)sum);
}
}


#include <iostream>
#define LL __int64

using namespace std;

LL euler(LL n)
{
LL res = n, a = n;

for(LL i = 2; i * i <= a; i++)  //没用LL,TLE两发
{
if(a % i == 0)
{
res = res / i * (i - 1);

while (a % i == 0)
{
a /= i;
}
}
}

if (a > 1)
{
res = res / a * (a - 1);
}

return res;
}

int main()
{
LL n, x;
while (~scanf("%I64d%I64d", &n, &x))
{
LL ans = euler(n + x + 1);
printf("%I64d\n", ans);
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  hdu-5597