bzoj 3529

 

感谢PoPoQQQ

 1 /**************************************************************
 2     Problem: 3529
 3     User: idy002
 4     Language: C++
 5     Result: Accepted
 6     Time:3568 ms
 7     Memory:3192 kb
 8 ****************************************************************/
 9  
10 #include <cstdio>
11 #include <algorithm>
12 using namespace std;
13  
14 struct Query {
15     int n, m, a, id;
16     bool operator<( const Query & b ) const {
17         return a<b.a;
18     }
19 };
20  
21 int prm[10000], isnot[100010], mu[100010], f[100010], h[100010], ptot;
22 int order[100010], cur;
23 int q, ans[20010];
24 Query qry[20010];
25  
26 bool cmp( int a, int b ) { return f[a]<f[b]; }
27 void modify( int pos, int delta ) {
28     for( int i=pos; i<=100000; i+=i&-i )
29         h[i] += delta;
30 }
31 int query( int pos ) {
32     int rt = 0;
33     for( int i=pos; i; i-=i&-i )
34         rt += h[i];
35     return rt;
36 }
37 void init( int n ) {
38     mu[1] = 1;
39     for( int i=2; i<=n; i++ ) {
40         if( !isnot[i] ) {
41             prm[++ptot] = i;
42             mu[i] = -1;
43         }
44         for( int j=1; j<=ptot && i*prm[j]<=n; j++ ) {
45             isnot[i*prm[j]] = true;
46             if( i%prm[j]==0 ) {
47                 mu[i*prm[j]] = 0;
48                 break;
49             }
50             mu[i*prm[j]] = -mu[i];
51         }
52     }
53     for( int i=1; i<=n; i++ )
54         for( int j=i; j<=n; j+=i )
55             f[j] += i;
56     for( int i=1; i<=n; i++ )
57         order[i] = i;
58     sort( order+1, order+1+n, cmp );
59 }
60  
61 int main() {
62     init(100000);
63     scanf( "%d", &q );
64     for( int i=1; i<=q; i++ ) {
65         scanf( "%d%d%d", &qry[i].n, &qry[i].m, &qry[i].a );
66         if( qry[i].n>qry[i].m ) swap( qry[i].n, qry[i].m );
67         qry[i].id = i;
68     }
69     sort( qry+1, qry+1+q );
70     for( int i=1; i<=q; i++ ) {
71         while( cur+1<=100000 && f[order[cur+1]]<=qry[i].a ) {
72             cur++;
73             int j=order[cur];
74             for( int k=j; k<=100000; k+=j )
75                 modify( k, f[j]*mu[k/j] );
76         }
77         int &tans = ans[qry[i].id];
78         int n = qry[i].n, m = qry[i].m;
79         for( int j=1; j<=n; j++ ) {
80             int jj=min( n/(n/j), m/(m/j) );
81             tans += (query(jj)-query(j-1))*(n/j)*(m/j);
82             j = jj;
83         }
84     }
85     for( int i=1; i<=q; i++ )
86         printf( "%d\n", ans[i]&((1U<<31)-1) );
87 }
View Code

 

posted @ 2015-03-31 14:35  idy002  阅读(300)  评论(0编辑  收藏  举报