Ultraviolet A 11609-Team (combined mathematics + binary property + Rapid power modulo)
Question: How many solutions are there for N people to select one or more people to participate in the competition, and one of them is the team leader? (If the contestants are identical but the team leader is different, this is also a case.) [1 <= n <= 10 ^ 9]
Analysis: This question needs to be easily solved after the nature of the combined formula is converted to the power modulo.
Code:
// Ultraviolet A 11609-team/* combination number formula + binary coefficient property + quick power manual push-> F [N] = C (n, 1) * 1 + C (n, 2) * 2 + C (n, n) * n-> F [N] = Σ (I * C (n, I )) -> F [N] = Σ (C (n, I) * C (I, 1)-> F [N] = N * Σ (C (n-1, i-1)-> F [N] = N * 2 ^ (n-1) Σ (C (n-1, I-1) 1 <= I <= n so is the complete set, = 2 ^ (n-1) */# include <cstdio> # include <cstring> # include <algorithm> using namespace STD; typedef unsigned long ull; # define mod extends %7ull pow_mod (ull A, ull B) {ull ans = 1; while (B) {If (B & 1) ans = ans * A % MOD; A = (a % mod) * (a % mod) % MOD; B >>= 1;} return ans;} void orz () {int CAS = 1, t; ull ans, N; scanf ("% d", & T); While (t --) {scanf ("% LlU", & N ); printf ("case # % d:", CAS ++); printf ("% LlU \ n", (pow_mod (2, n-1) * n) % mod );}} int main () {orz (); Return 0 ;}
Code Jun
Ultraviolet A 11609-Team (combined mathematics + binary property + Rapid power modulo)