Project Euler Problem 48 method of processing multiplication to explode long long

Source: Internet
Author: User



The wretched thing about this problem is that you can explode a long long with the fast power middle process.

But I have a way of dealing with a long long.

It's no problem to use a two-point method when you multiply. See Code


#include <iostream> #include <cstdio> #include <cstring> #include <ctime> #include <cstdlib&
Gt  #include <algorithm> #include <stack> #include <cmath> #include <vector> #define EPS 1e-6 #define
INF 1000000007 #define PI acos ( -1.0) using namespace std;
Long Long mod = 10000000000LL;
    Long long multi (long long A, long long B, long long C) {long long ret = 0;
            while (b) {if (b & 1) {ret + = A;
        if (ret >= c) ret-= C;
        } A + = A;
        if (a >= c) A-= C;
    b >>= 1;
} return ret;
    } Long Long Fastmod (long long A, long long B, long long c)//a^b mod C {Long long ret = 1;
    a%= C;
    for (; b; b >>= 1, a = multi (A, A, c)) if (b & 1) ret = multi (ret, A, c);
return ret;
    } int main () {long long sum = 0;
  for (int i = 1; I <=, i++) sum = (sum + fastmod (i, I, MoD))% MoD;  cout << sum << endl;
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.