Ultraviolet A 11609-Team (combined mathematics + binary property + Rapid power modulo)

Source: Internet
Author: User

 

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.