Codeforces Round #428 (Div. 2) D. Winter is here[number theory II]

Source: Internet
Author: User
Tags gcd

Title: Http://codeforces.com/contest/839/problem/D

Test instructions: Find out each case makes all numbers GCD not 1, the contribution to the answer is GCD value multiplied by number.

The problem: Because the number is not large, you can hash out the number of each number, and then forward, F[i] represents the number of numbers that exist at gcd==i. Each time I calculate I, subtract the calculated number of species, so it is calculated from the back forward. Each number contribution number is ${2}^{sum-1}$ (the case of write binary number can be observed), all the numbers contribute to $sum*{2}^{sum-1}$ 2 times x times can be pre-processed to modulo out.

1 #define_crt_secure_no_deprecate2 #pragmaComment (linker, "/stack:102400000,102400000")3#include <iostream>4#include <cstdio>5#include <fstream>6#include <iomanip>7#include <algorithm>8#include <cmath>9#include <deque>Ten#include <vector> One#include <bitset> A#include <queue> -#include <string> -#include <cstring> the#include <map> -#include <stack> -#include <Set> -#include <functional> + #definePII Pair<int, int> - #defineMoD 1000000007 + #defineMP Make_pair A #definePi ACOs (-1) at #defineEPS 0.00000001 - #defineMST (A,i) memset (A,i,sizeof (a)) - #defineAll (n) n.begin (), N.end () - #defineLson (x) ((x<<1)) - #defineRson (x) ((x<<1) | |) - #defineINF 0x3f3f3f3f intypedefLong Longll; -typedef unsignedLong Longull; to using namespacestd; + Const intMAXN = 1e6 +5; - ll SAVEPOW[MAXN]; the intCNT[MAXN]; * ll F[MAXN]; $ intMain ()Panax Notoginseng { -Ios::sync_with_stdio (false); theCin.tie (0); Cout.tie (0); +     intI, J, K, M, N; ACIN >>N; the      for(inti =1; I <= N; ++i) +     { -CIN >>K; $cnt[k]++; $     } -savepow[0] =1; -      for(inti =1; I <=1000000; ++i) Savepow[i] = (Savepow[i-1] <<1) %MoD; thell ans =0; -      for(LL i =1000000; i >1; --i)Wuyi     { the         intsum =0; -          for(intj = i; J <= Maxn; J + =i) WuSum + =Cnt[j]; -         if(sum) About         { $ll Tempans =0; -Tempans = 1LL * Sum*savepow[sum-1] %MoD; -              for(intj = i + i; J <= Maxn; J + =i) -Tempans = (Tempans-f[j] + MoD)%MoD; AF[i] =Tempans; +Ans = (ans + i*f[i])%MoD; the         } -     } $cout << ans <<Endl; the     return 0; the}

Codeforces Round #428 (Div. 2) D. Winter is here[number theory II]

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.