Zoj 2836 number puzzle)

Source: Internet
Author: User

 

Zoj 2836 number puzzle)

 

 

 

#include <cstdio>#include <cstring>#include <algorithm>using namespace std;typedef long long LL;#define CLR( a, b ) memset( a, b, sizeof(a) )int m, n, A[11];LL gcd( LL a, LL b ){    return b == 0 ? a : gcd( b, a % b );}LL lcm( LL a, LL b ){    return a / gcd( a, b ) * b;}void solve(){    LL ans = 0;    for( int i = 1; i < ( 1 << n ); ++i )    {        LL mult = 1;        LL bits = 0;        for( int j = 0; j < n; ++j )        {            if( ( 1 << j ) & i )            {                mult = lcm( mult, A[j] );                bits++;            }        }        if( bits & 1 )            ans += m / mult;        else            ans -= m / mult;    }    printf( "%lld\n", ans );}void Orz(){    while( ~scanf( "%d %d", &n, &m ) )    {        for( int i = 0; i < n; ++i )            scanf( "%d", &A[i] );        solve();    }}int main(){    Orz();    return 0;}
Code Jun

 

Zoj 2836 number puzzle)

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.