hdu 5597(欧拉,找规律)
2015-12-12 22:57
375 查看
hdu 5597
打表f(x) = x + 1,找规律,欧拉函数
打表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; }
相关文章推荐
- android轻量级开源缓存框架——ASimpleCache(ACache)源码分析
- 【java基础】关于java使用unicode编码及java编码解码测试数据
- ruby基础语法
- listview控件的使用(1)------最简单的listview的使用
- iOS讲解迷惑--Swift中枚举、继承、协议
- C++ Map容器
- Activity和Fragement中onSaveInstanceState()的使用详解
- jQuery方式事件冒泡的2个方法
- C++0x尝鲜:lambda表达式
- 环回接口 环回地址 环回路由
- [matlab] 基础与应用笔记2
- Android
- js 滚动加载iframe框中内容
- Linux网络配置与管理
- C++11尝鲜:std::move和std::forward源码分析
- Java新手学习路线
- 浅谈功能测试流程
- HDU 5596:GTW likes gt
- Android studio 启动APP选择设备列表中没有可选设备的解决方案
- Android ShareSDK分享