hdu 5597(欧拉,找规律)

来源:互联网 发布:手机截图软件 编辑:程序博客网 时间:2024/04/17 06:59

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 __int64using 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;}
0 0
原创粉丝点击