NYOJ 420 P power summation

Source: Internet
Author: User

P power summation time limit: 1000 MS | memory limit: 65535 KB difficulty: 3

Description
A very simple question: 1 ^ p + 2 ^ p + 3 ^ p + ...... + The sum of n ^ p.
Input
A separate number t in the first line indicates the number of test data groups. Next, there will be t rows of numbers, each line includes two numbers n, p,
Input 0
Output
Output 1 ^ p + 2 ^ p + 3 ^ p + ...... + N ^ p returns the remainder of 10003, and each result occupies a single row.
Sample Input
210 110 2
Sample output
55385
AC code:
# Include
      
       
# Define N 10003int main () {long T, n, p, I, B, t, a, sum; // long longscanf ("% d ", & T); while (T --) {scanf ("% lld", & n, & p); if (n = 0) // md, potholes, the question n is greater than 0 !!! Printf ("0 \ n"); continue;} sum = 1; for (I = 2; I <= n; I ++) {a = I; B = p; t = 1; while (B) {if (B & 1) t = (t * a) % N; a = (a * a) % N; B = B/2;} sum = (sum + t) % N;} printf ("% d \ n", sum);} return 0 ;}
      


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.