http://lightoj.com/volume_showproblem.php?problem=1213  Fantasy of a Summation Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Practice LightOJ 1213 Description If you think codes, eat codes then sometimes you…
https://www.cnblogs.com/zhengguiping--9876/p/6015019.html LightOj 1213 - Fantasy of a Summation(推公式 快速幂) 我们很容易就知道最内层的加法式子执行了n^K次,每次加了K个数,所以一共加了K*n^K个数,一共有n个数,每个数加的次数一定是相同的,所以每个数都加了K*n^(K-1)次,所以结果就是Sum*K*n^(K-1)%mod; 快速幂求一下即可:…
题目链接:http://lightoj.com/volume_showproblem.php?problem=1213 #include <stdio.h> int cases, caseno; int n, K, MOD; int A[1001]; int main() { scanf("%d", &cases); while( cases-- ) { scanf("%d %d %d", &n, &K, &MOD); i…
1213 - Fantasy of a Summation         If you think codes, eat codes then sometimes you may get stressed. In your dreams you may see huge codes, as I have seen once. Here is the code I saw in my dream. #include <stdio.h> int cases, caseno;int n, K, M…
http://lightoj.com/volume_showproblem.php?problem=1282 Leading and Trailing Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Practice LightOJ 1282 Description You are given two integers: n and k, your task is t…
题目链接:https://vjudge.net/problem/LightOJ-1213 1213 - Fantasy of a Summation    PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB If you think codes, eat codes then sometimes you may get stressed. In your dreams you may see hug…
/** 题目:Fantasy of a Summation 链接:https://vjudge.net/contest/154246#problem/L 题意:n个数,k层重复遍历相加.求它的和%mod的值: 思路:很容易想到n个数出现在要加的和中的次数相同. 又所有数的出现次数为n^k * k: 所以每个数出现的次数为n^k * k / n; */ #include<iostream> #include<cstring> #include<cstdio> #inclu…
题解:根据题目给的程序,就是计算给的这个序列,进行k次到n的循环,每个数需要加的次数是k*n^(k-1),所以快速幂取模,算计一下就可以了. #include <bits/stdc++.h> using namespace std; typedef long long ll; const int INF = 0x3f3f3f3f3f; long long pow_mod(ll a, ll k, ll mod) { ll ans = 1; while(k) { if(k%2) ans *= a;…
题意: 首先 只看第一层循环的A[0],是不是用了nk-1次  A[1]也是用了nk-1次······ 所以 第一层的sum(A[i]的和) 一共用了nk-1 所以第一层为sum * nk-1 因为又k层循环 所以全部为sum * nk-1 * k 最后不要忘了 % MOD 代码如下: #include <iostream> #include <cstdio> #include <cmath> #include <algorithm> #define mem…
题目链接:http://lightoj.com/volume_showproblem.php?problem=1245 题意就是求 n/i (1<=i<=n) 的取整的和这就是到找规律的题, i     1  2   3   4   5   6   7    8 a    8  4   2   2   1   1   1    1 你可以多写几组你会发现 有8-4个1:4-2个2:...其他例子也是这样: 当n = 10时 n/1 = 10, n/2 = 5说明(5, 10]这个前开后闭的区间…
http://lightoj.com/volume_showproblem.php?problem=1336 Sigma Function Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Practice LightOJ 1336 Description Sigma function is an interesting function in Number Theor…
lightoj 1010 Knights in Chessboard 链接:http://lightoj.com/volume_showproblem.php?problem=1010 题意:国际象棋规则,在 m*n 的格子放某一棋子,棋子可以沿着它的8个方位直走,问盘子可以放多少个这样的棋子而使任意两个不发生冲突. 思路:数学水题,找下算出几组,找下规律就出来了.值得注意的是有特判. 代码: #include <iostream> #include <cstdio> #inclu…
题目链接:https://vjudge.net/contest/28079#problem/M 题目大意: 一个边界长为L宽为W的平面同时发射n个台球,运动K秒,台球碰到桌面及两(多)个台球相撞情况如下图所示,求K秒后这n个球的位置(要排序,依次按横纵坐标升序): 解题思路:其实跟以前的经典题蚂蚁爬木棍是一样的,总结为以下几点: ①两(多)球相撞的情况可以忽略,因为两球撞击后可以看作两个球按原来的方向运动只是序号换了一下而已,多球同理. ③碰壁时反向 ②可以把横纵坐标分开计算,这样就很明了了,可…
链接: https://vjudge.net/problem/LightOJ-1294 题意: Given two integers: n and m and n is divisible by 2m, you have to write down the first n natural numbers in the following form. At first take first m integers and make their sign negative, then take nex…
链接: https://vjudge.net/problem/LightOJ-1299 题意: 考虑成,U位置的点要往后放,D位置往前放 Dp[i][j]表示处于i位置,还有j个U没有放下. s[i] == 'D' : Dp[i][j] = Dp[i-1][j]j+Dp[i-1][j+1](j+1) 把d放到前面空出来j的位置中的一个,或者是j+1中的一个同时j+1中的一个U再放下来. s[i] == 'U' : Dp[i][j] = Dp[i-1][j-1]+Dp[i-1][j]*j 拿起当前…
度度熊保护村庄 Accepts: 13 Submissions: 488 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Problem Description 哗啦啦村袭击了喵哈哈村! 度度熊为了拯救喵哈哈村,带着自己的伙伴去救援喵哈哈村去了!度度熊与伙伴们很快的就过来占据了喵哈哈村的各个军事要地,牢牢的守住了喵哈哈村. 但是度度熊发现,这是一场旷日持久的战斗,所以度度熊决定要以逸…
题目链接 :http://acm.hdu.edu.cn/showproblem.php?pid=6030 Problem Description Little Q wants to buy a necklace for his girlfriend. Necklaces are single strings composed of multiple red and blue beads. Little Q desperately wants to impress his girlfriend,…
题目链接 Problem Description Function Fx,ysatisfies: For given integers N and M,calculate Fm,1 modulo 1e9+7. Input There is one integer T in the first line. The next T lines,each line includes two integers N and M . 1<=T<=10000,1<=N,M<2^63. Output…
P1447开关灯泡 Accepted 标签:CSC WorkGroup III[显示标签] 描写叙述 一个房间里有n盏灯泡.一開始都是熄着的,有1到n个时刻.每一个时刻i,我们会将i的倍数的灯泡改变状态(即原本开着的现将它熄灭,原本熄灭的现将它点亮),问最后有多少盏灯泡是亮着的. 格式 输入格式 一个数n 输出格式 m,表示最后有m盏是亮着的 例子1 例子输入1[复制] 5 例子输出1[复制] 2 限制 1s 提示 范围:40%的数据保证,n<=maxlongint 100%的数据保证,n<=…
参考博客:http://www.cnblogs.com/Sunshine-tcf/p/5737627.html. 说实话,官方博客的推导公式看不懂...只能按照别人一样打表找规律了...但是打表以后其实也不是很好看出规律的...而且这个表都写了半天233...(真是太弱了= =)为了打表,我们应当先知道k数列必须是不递减的才能满足值不为0,因此我们可以用递归来写这个表(类似于dfs). AC代码如下: #include <stdio.h> #include <algorithm>…
题意:已知F0 = 0,F1 = 1,Fn = Fn - 1 + Fn - 2(n >= 2), 且若n=Fa1+Fa2+...+Fak where 0≤a1≤a2≤⋯≤a,n为正数,则n为mjf-good,否则为mjf-bad,给定k,求最小的mjf-bad. 分析:找规律可得,F2*k+3 - 1,矩阵快速幂即可. #include<cstdio> #include<cstring> #include<cstdlib> #include<cctype&g…
Number Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 187893    Accepted Submission(s): 46820 Problem Description A number sequence is defined as follows: f(1) = 1, f(2) = 1, f(n) = (A…
题意:将一个字符串分割成最少的字符串,使得分割出的每个字符串都是回文串.输出最小的分割数. 方法(自己的):先O(n^2)(用某个点或某个空区间开始,每次向左右扩展各一个的方法)处理出所有子串是否回文.然后常规区间dp,ans[i][j]表示i到j的子串的最小划分数.如果i到j的子串本身为回文串,那么ans[i][j]为1,否则枚举所有方案将i到j划分为两个区间,取所有两个区间结果之和的最小值. 方法(其他,大概就是压了一下空间,压了一下时间的常数):http://blog.csdn.net/l…
POJ1338 2545 2591 2247都是一个类型的题目,所以放到一起来总结 POJ1338:Ugly Numbers Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 21708   Accepted: 9708 Description Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequence  1, 2, 3, 4,…
链接: https://vjudge.net/problem/LightOJ-1282 题意: You are given two integers: n and k, your task is to find the most significant three digits, and least significant three digits of nk. 思路: 后三位快速幂取余,考虑前三位. \(n^k\)可以表示为\(a*10^m\)即使用科学计数法. 对两边取对数得到\(k*log…
http://codeforces.com/problemset/problem/992/C 题意: 给你两个数x,k,k代表有k+1个月,x每个月可以增长一倍,增长后的下一个月开始时x有50%几率减1,增长k+1个月后结果是每种情况的总和除以种数. 题目要求的是增长k+1个月后的结果. 我们根据第三个样例可以推出他的增长过程 3 6 5 12 11 10 9 |     |     | | 24    22 20 18 从这个推导我们容易得出最后得到的每种情况构成一个等差数列,公差为2 结果是…
        ID Origin Title   111 / 423 Problem A LightOJ 1370 Bi-shoe and Phi-shoe   21 / 74 Problem B LightOJ 1356 Prime Independence   61 / 332 Problem C LightOJ 1341 Aladdin and the Flying Carpet   54 / 82 Problem D LightOJ 1336 Sigma Function   66 /…
KUANGBIN带你飞 全专题整理 https://www.cnblogs.com/slzk/articles/7402292.html 专题一 简单搜索 POJ 1321 棋盘问题    //2019.3.18 POJ 2251 Dungeon Master POJ 3278 Catch That Cow  //4.8 POJ 3279 Fliptile POJ 1426 Find The Multiple  //4.8 POJ 3126 Prime Path POJ 3087 Shuffle…
模版整理: 晒素数 void init() { cas = ; ; i < MAXD ; i++) is_prime[i] = true; is_prime[] = is_prime[] = false; ; i < MAXD ; i++) { if (is_prime[i]) { prime[cas++] = i; for (int j = i + i ; j < MAXD ; j += i) is_prime[j] = false; } } } 合数分解 int x = src[i]…
[kuangbin带你飞]专题1-23 专题一 简单搜索 POJ 1321 棋盘问题POJ 2251 Dungeon MasterPOJ 3278 Catch That CowPOJ 3279 FliptilePOJ 1426 Find The MultiplePOJ 3126 Prime PathPOJ 3087 Shuffle'm UpPOJ 3414 PotsFZU 2150 Fire GameUVA 11624 Fire!POJ 3984 迷宫问题HDU 1241 Oil Deposit…