HDU 4135-Co-prime, hdu4135-co-prime

Source: Internet
Author: User

HDU 4135-Co-prime, hdu4135-co-prime

Question link: Portal

Question: calculate the number of the numbers in the interlace with n in the range [a, B.

Concept: calculate the number of mutual quality between [1-B] and n-the number of mutual quality between [1-(A-1.


#include <algorithm>#include <iostream>#include <cstring>#include <cstdlib>#include <string>#include <cctype>#include <vector>#include <cstdio>#include <cmath>#include <queue>#include <stack>#include <map>#include <set>#define maxn 360#define _ll __int64#define ll long long#define INF 0x3f3f3f3f#define Mod 1000000007#define pp pair<int,int>#define ull unsigned long long#define max(x,y) ( ((x) > (y)) ? (x) : (y) )#define min(x,y) ( ((x) > (y)) ? (y) : (x) )using namespace std;_ll fac[maxn],tot,A,B,N,ans;void div(int x){tot=0;for(_ll i=2;i*i<=x;i++){if(x&&x%i==0){fac[tot++]=i;while(x&&x%i==0)x/=i;}}if(x>1)fac[tot++]=x;}void dfs(_ll num,_ll s,_ll r,_ll n){if(num==tot){if(s&1)ans-=n/r;else ans+=n/r;return ;}dfs(num+1,s,r,n);dfs(num+1,s+1,r*fac[num],n);}int cas=1;void solve(){div(N);ans=0;dfs(0,0,1,B);_ll ans_1_b=ans;ans=0;dfs(0,0,1,A-1);_ll ans_1_a=ans;printf("Case #%d: %I64d\n",cas++,ans_1_b-ans_1_a);}int main(){int T;scanf("%d",&T);while(T--){scanf("%I64d%I64d%I64d",&A,&B,&N);solve();}return 0;}

Related Article

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.