标签:style blog http io color os ar for sp
input | output |
---|---|
3 6 |
4 |
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #include<queue> #include<vector> #include<set> #include<stack> #include<map> #include<ctime> #include<bitset> #define LL long long #define INF 999999 #define maxn 500010 using namespace std; LL get(LL n,LL MAX) { vector<LL>q; LL num=n,ans=0,tt ; for(LL i = 2 ; i*i <= n ;i++)if(n%i==0) { while(n%i==0) { n /= i ; } q.push_back(i) ; } if(n>1)q.push_back(n) ; int m = q.size(); int len=(1<<m) ,e ; for( int i = 1 ; i < len ;i++) { e=0; tt=1; for( int j = 0 ; j < m ;j++)if((1<<j)&i) { tt *= q[j] ; e++; } if(e&1) ans += MAX/tt ; else ans -= MAX/tt ; } return ans; } int main() { int i,j,k; LL n ,a,ans ; while(cin >> a >> n) { if(a&1) ans=(n+1)/2 ,n/=2; else ans=0; ans += get(a,n) ; cout << ans<<endl; } }
标签:style blog http io color os ar for sp
原文地址:http://www.cnblogs.com/20120125llcai/p/4057885.html