Topic Link: POINT here!!!
Test instructions
give you an interval [a, b] (1<=A<=B<=1E15), an X (X<=1E9). Ask you how many numbers and X coprime are in the interval [a, b].
Exercises
1, we first find out all the quality factors of x, note that X has a maximum of 1 factors greater than (sqrt (x)), so we can first preprocess [1,sqrt (1E9)] all prime numbers.
2, then we decompose the X-Factor and down, the last remaining is either 1, or is greater than sqrt (x) of the quality factor.
3, we get a quality factor of up to 15 or so, we directly use the capacity of the Scout to engage in it. We get the number of Inma with X, minus the total.
Code
#include <cstdio> #include <cstring> #include <iostream> #include <sstream> #include < algorithm> #include <vector> #include <bitset> #include <set> #include <queue> #include < stack> #include <map> #include <cstdlib> #include <cmath> #define PI 2*asin (1.0) #define LL Long long# Define PB push_back#define pa pair<int,int> #define CLR (A, B) memset (A,b,sizeof (a)) #define Lson lr<<1,l,mid# Define Rson Lr<<1|1,mid+1,r#define Bug (x) printf ("%d++++++++++++++++++++%d\n", x,x) #define Key_value Ch[ch[root ][1]][0]c:\program files\git\binconst ll MOD = 1e9+7;const ll N = 3e4+5000;const int MAXN = 5e5+15;const int letter = 130 ; const int INF = 1e17;const double Pi=acos ( -1.0); const double eps=1e-10;using namespace Std;inline int read () {int x=0, F=1;char Ch=getchar (); while (ch< ' 0 ' | | Ch> ' 9 ') {if (ch== '-') F=-1;ch=getchar ();} while (ch>= ' 0 ' &&ch<= ' 9 ') {x=x*10+ch-' 0 '; Ch=getchar ();} return x*f;} LL a,b;int X;int Vis[n],Cnt=0;int prime[10000],ps[32];void init () {vis[1]=1; for (int i=2;i<n;i++) {if (!vis[i]) prime[++cnt]=i; for (int j=1;j<=cnt&&i*prime[j]<n;j++) {vis[prime[j]*i]=1; if (i%prime[j]==0) break; }}}int Main () {init (); int t,cas=0; scanf ("%d", &t); while (t--) {scanf ("%i64d%i64d%d", &a,&b,&x); int num=0; for (int i=1;i<=cnt;i++) {if (x%prime[i]==0) {while (x%prime[i]==0) {X/=prime [i]; } Ps[num++]=prime[i]; }} if (X!=1) ps[num++]=x; LL Sum=b-a+1ll; LL tt=0; for (int i=1;i< (1<<num); i++) {int cc=0; LL Ans=1; for (int j=0;j<num;j++) {if (i& (1<<j)) {cc++; ANS*=1LL*PS[J]; }} if (cc&1) tt=tt+ (b/ans-(A-1)/ans); ElseTt=tt-(b/ans-(A-1)/ans); } printf ("Case #%d:%i64d\n", ++CAS,SUM-TT); } return 0;} /*1003 15 12*/
give you an interval [a, b] (1<=A<=B<=1E15), an X (X<=1E9). Ask you how many numbers and X coprime are in the interval [a, b].
Exercises
1, we first find out all the quality factors of x, note that X has a maximum of 1 factors greater than (sqrt (x)), so we can first preprocess [1,sqrt (1E9)] all prime numbers.
2, then we decompose the X-Factor and down, the last remaining is either 1, or is greater than sqrt (x) of the quality factor.
3, we get a quality factor of up to 15 or so, we directly use the capacity of the Scout to engage in it. We get the number of Inma with X, minus the total.
Code
hdu4135 co-prime (Rong Chi)