7_13_P题 Hack it!(数学)
2016-09-04 15:40
459 查看
7_13_P题 Hack it!
简单题意
设f(x),是x每一位上的数之和,求一个区间l,r,使∑ri=lf(i) mod n=0, n为输入思路
很显然f(1018+x)−f(x)=1所以有∑1018+xi=xf(i)=∑1018i=1f(i)+∑xi=1f(1018+i)−f(i)
整理得∑1018+xi=xf(i)=∑1018i=1f(i)+x
令sum=∑1018i=1f(i)
则有∑1018+xi=xf(i)=sum+x
令x=(n−sum mod n)mod n
则解就是[1+x,1018+x]
代码
Pythonn = int(input()) r = 45*18*10**17; l = n-r%n r = l +10**18-1 print(l,r)
CPP
#include <iostream> using namespace std; typedef long long ll; const ll maxn = 1e17; int main (){ ll n; cin >>n; ll l = n - 9LL*(5LL*(9LL*(2LL*maxn%n)%n)%n)%n; ll r = l+1e18-1; cout << l <<" "<<r <<endl; return 0; }
相关文章推荐
- 值得学习的blog
- ubuntu使用超级管理员root登录
- Redis探索之旅(8)- Redis数据类型之哈希表
- 7_13_M题 Expedition(贪心、优先队列)
- 7_13_K题 Palindromes(模拟)
- CodeForces 456D Elections(字典树+dp)
- JavaScript学习小结
- 7_13_G题 Median(二分)
- CodeForces 691D Swaps in Permutation(并查集)
- 快速傅里叶变换(FFT)和数论变换(NTT)模板
- Poj 3070 Fibonacci (矩阵快速幂)
- 7_13_F题 K Best(二分、最大化平均值)
- Java 面试题和答案 - (下)
- Sticks
- Leetcode #3 Longest Substring Without Repeating Characters
- 深入分析AsyncTask
- yii框架循环添加只能加入最后一条的解决办法
- Find the difference——Difficulty:Easy
- 7_13_E题 Pie(二分)
- HBase协处理器