[NOI2016] The beauty of cycle

portal

I'm so tired, I don't want to write a solution, put a portal

I heard this is a template question

Why are your template questions so difficult?

How do I do template questions for a day?

I don’t know if it’s been too long since I did math problems, and I couldn’t even list a persimmon for a long time.

Wait until I finally know what I want to do, and then watch k^x=1(mod j) for a long, long time

Leng did not see that gcd(k,j)==1

Am I a pig head (

Then start pushing a fake persimmon

Pushed for a long time

Called out and tuned the sample

After trying a few small data, I found that the persimmon was wilted, and I had to make 40*nlog, trying to struggle. fruitless

Copy the problem

I found that I completely forgot that there is such a thing as a coprime dp transfer from the first i prime factors

It's so badass

A few days ago, I did a question in the morning, in the afternoon or in the evening. Now I do one question a day. I'm afraid I don't want to stand shoulder to shoulder with the sun.

  1 //Achen
  2 #include<algorithm>
  3 #include<iostream>
  4 #include<cstring>
  5 #include<cstdlib>
  6 #include<vector>
  7 #include<cstdio>
  8 #include<queue>
  9 #include<cmath>
 10 #include<set>
 11 #include<map>
 12 #define For(i,a,b) for(int i=(a);i<=(b);i++)
 13 #define Rep(i,a,b) for(int i=(a);i>=(b);i--)
 14 const int N=2e6+7,up=2e6;
 15 typedef long long LL; 
 16 typedef double db;
 17 using namespace std;
 18 int p[N],bo[N],mu[N],q[N];
 19 LL smu[N],n,m,k;
 20 
 21 template<typename T> void read(T &x) {
 22     char ch=getchar(); x=0; T f=1;
 23     while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
 24     if(ch=='-') f=-1,ch=getchar();
 25     for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0'; x*=f;
 26 }
 27 
 28 void get_prime() {
 29     mu[1]=1;
 30     For(i,2,up) {
 31         if(!bo[i]) { p[++p[0]]=i; mu[i]=-1; }
 32         for(int j=1;j<=p[0]&&p[j]*i<=up;j++) {
 33             bo[p[j]*i]=1;
 34             mu[p[j]*i]=-mu[i];
 35             if(i%p[j]==0) {
 36                 mu[p[j]*i]=0;
 37                 break;
 38             }
 39         }
 40     }
 41     For(i,1,up) smu[i]=smu[i-1]+mu[i];
 42 }
 43 
 44 void get_it(int k) {
 45     for(int i=1;p[i]<=k;i++) 
 46         if(k%p[i]==0) q[++q[0]]=p[i];
 47 }
 48 
 49 map<int,LL>mp;
 50 LL get_M(int n) {
 51     if(n<=up) return smu[n];
 52     if(mp[n]) return mp[n];
 53     LL rs=0;
 54     for(int i=2;i<=n;) {
 55         int l=i,r=n/(n/i);
 56         rs+=(LL)(r-l+1)*get_M(n/i);
 57         i=r+1;
 58     }
 59     rs=1-rs;
 60     mp[n]=rs; return rs;
 61 }
 62 
 63 map<LL,int>S[10],T[10];
 64 LL get_S(int i,int n) {
 65     if(n<=0) return 0;
 66     if(i==0) return get_M(n);
 67     if(S[i].count(n)) return S[i][n];
 68     return (S[i][n]=get_S(i-1,n)+get_S(i,n/q[i]));
 69 }
 70 
 71 LL get_T(int i,int n) {
 72     if(n<=1) return n;
 73     if(i==0) return n;
 74     if(T[i].count(n)) return T[i][n];
 75     return (T[i][n]=get_T(i-1,n)-get_T(i-1,n/q[i]));
 76 }
 77 
 78 LL solve() {
 79     LL rs=0;
 80     int tup=min(n,m);
 81     LL pr=0;
 82     for(int i=1;i<=tup;) {
 83         int l=i,r=min(n/(n/i),m/(m/i));
 84         LL tps=get_S(q[0],r);
 85         rs=rs+(LL)(n/i)*(tps-pr)*get_T(q[0],m/i);
 86         i=r+1; pr=tps;
 87     }
 88     return rs;
 89 }
 90 
 91 #define DEBUG
 92 int main() {
 93 #ifdef DEBUG
 94     freopen("1.in","r",stdin);
 95     //freopen(".out","w",stdout);
 96 #endif
 97     read(n); read(m); read(k);
 98     get_prime();
 99     get_it(k);
100     printf("%lld\n",solve());
101     return 0;
102 }
View Code

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325343719&siteId=291194637