等比数列

hoj3152-Dice 等比数列求和取模

怎甘沉沦 提交于 2020-02-28 05:08:22
http://acm.hit.edu.cn/hoj/problem/view?id=3152 Dice My Tags (Edit) Source : Time limit : 1 sec Memory limit : 128 M Submitted : 82, Accepted : 18 You have a dice with M faces, each face contains a distinct number. Your task is to calculate the expected number of tosses until a number facing up for consecutive N times. We assume when we tossing the dice, each face will occur randomly and uniformly. Input Each test cases contains only one line with two integers M, N. (1<=M, N<=100000000) Output For each test case, display a single line with the answer to the question above, the answer maybe very

等比数列二分求和取模

和自甴很熟 提交于 2020-01-06 21:04:41
题意: Given a n × n matrix A and a positive integer k , find the sum S = A + A 2 + A 3 + … + A k . n ( n ≤ 30), k ( k ≤ 10 9 ) and m ( m < 10 4 ) 输出结果矩阵 解法: 若 n是偶数 Sn= a+...+an/2 + an/2+1 + an/2+2 +...+ an/2+n/2 =(a+...+an/2) + an/2(a+...+an/2) =Sn/2+ an/2Sn/2 =(1+an/2)Sn/2等比数列二分求和取模 2) 若n是奇数 Sn= a+...+a(n-1)/2 + a(n-1)/2+1 +... + a(n-1)/2+(n-1)/2 + a(n-1)/2+(n-1)/2 + 1 =S(n-1)/2 + a(n-1)/2(a+...+a(n-1)/2)+an =(1+a(n-1)/2)S(n-1)/2+an //#include <bits/stdc++.h> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <iostream> #include <algorithm> #include <iostream>

等比数列二分求和取模

雨燕双飞 提交于 2020-01-05 00:30:26
题意: Given a n × n matrix A and a positive integer k , find the sum S = A + A 2 + A 3 + … + A k . n ( n ≤ 30), k ( k ≤ 10 9 ) and m ( m < 10 4 ) 输出结果矩阵 解法: 若 n是偶数 Sn= a+...+an/2 + an/2+1 + an/2+2 +...+ an/2+n/2 =(a+...+an/2) + an/2(a+...+an/2) =Sn/2+ an/2Sn/2 =(1+an/2)Sn/2等比数列二分求和取模 2) 若n是奇数 Sn= a+...+a(n-1)/2 + a(n-1)/2+1 +... + a(n-1)/2+(n-1)/2 + a(n-1)/2+(n-1)/2 + 1 =S(n-1)/2 + a(n-1)/2(a+...+a(n-1)/2)+an =(1+a(n-1)/2)S(n-1)/2+an //#include <bits/stdc++.h> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <iostream> #include <algorithm> #include <iostream>

用 np.logspace() 创建等比数列

不打扰是莪最后的温柔 提交于 2019-12-15 14:12:02
np .logspace ( start , stop , num = 50 , endpoint = True , base = 10.0 , dtype = None , axis = 0 , ) Docstring:   Return numbers spaced evenly on a log scale.   In linear space, the sequence starts at ``base ** start`` (`base` to the power of `start`) and ends with ``base ** stop`` (see `endpoint` below). 等比数列通项为:a n = a 1 * q n-1 来源: https://www.cnblogs.com/shanger/p/12043959.html

2019E1_G 等比数列求和

雨燕双飞 提交于 2019-12-02 12:04:55
等比数列求和 题目 已知 a i = a 1 × q i − 1 a_{i}=a_{1}×q^{i-1} a i ​ = a 1 ​ × q i − 1 ,求 s u m i = 1 n a i sum_{i=1}^{n}a_{i} s u m i = 1 n ​ a i ​ 结果可能很大,请对987654323取模 输入 第一行一个正整数t,表示数据组数 接下来t行,每行三个整数 n , a 1 , q n,a_{1},q n , a 1 ​ , q 。 ( 0 < n , a 1 , q < 1 0 9 , 0 < t < 10000 ) (0<n,a_{1},q<10^{9},0<t<10000) ( 0 < n , a 1 ​ , q < 1 0 9 , 0 < t < 1 0 0 0 0 ) 输出 t 行,每行输出一个整数,表示等比数列的和 mod 987654323 的值。 输入样例 2 3 2 7 3 2 1 输出样例 114 6 思路 这里只给分治做法。 设等比数列和为 S S S 当n为偶数的时候 S n = S n / 2 + a n / 2 + 1 × S n / 2 S_{n}=S_{n/2}+a_{n/2+1}×S_{n/2} S n ​ = S n / 2 ​ + a n / 2 + 1 ​ × S n / 2 ​ 当n为奇数的时候 S n = S n

9.13 Test——NOIP模拟赛

孤街浪徒 提交于 2019-11-29 13:40:39
T1:backpack NYG的背包 【问题描述】 NYG有一个神奇的背包,每放进去一个物品,背包的体积就会变大。 也就是说,每放进一个物品,背包会被占用一定的体积,但是紧接着背包的总体积又会增大一定的值(注意是在放入物品后背包总体积才增大)。 NYG发觉这个背包十分好用,于是不由自主地想到了一个问题。 现在给出背包初始容量V 以及n个物品,每一个物品两个值a, b,分别表示物品所占体积 和放入背包后背包增大的体积。 NYG想知道能否把所有物品装进去? 因为NYG比较老实,这么简单的问题自然装作不会做的样子。 于是他来请教你。 【输入格式】 从文件backpack.in中读入数据 输入文件包含多组数据。 第一行一个数T表示数据组数。 对于每组数据,第一行两个数n, h,接下来n行每行两个数a, b表示物品所占体积和放入背包后背包增大的体积。 【输出格式】 输出到文件backpack.out中 对于每一组数据,如果能把所有物品装进去,输出"Yes",否则输出"No"(不包含引号) 【样例输入1】 3 5 3 1 4 8 8 3 【样例输出1】 Yes 【样例输入2】 3 7 9269 21366 1233 7178 23155 16679 23729 15062 28427 939 6782 24224 9306 22778 13606 5 22367 17444 5442