xdu 1022(數論篩法),xdu1022

來源:互聯網
上載者:User

xdu 1022(數論篩法),xdu1022

1022: A simple math problem 2時間限制: 1 Sec  記憶體限制: 128 MB
提交: 73  解決: 13
[提交][狀態][討論版]題目描述高斯函數: [x]表示,小於等於x的最大整數,即向下取整。 如 [2.5]=2,[1.2]=1等。 定義函數f(n)=[n/1]+[n/2]+[n/3]+...+[n/n] . sum(a,b)=f(a)+f(a+1)+...+f(b) 給定a,b,求sum(a,b)輸入多組輸入(不超過10000組) 每行輸入 a,b,其中1<=a<=b<=1000000輸出多組輸出 每行輸出sum(a,b)%1007,並換行範例輸入
1 11 2
範例輸出
14
提示

來源

令f(n)的含義實際上是有多少對(a,b)滿足a*b<=n(自己沒想到,在叉姐指導下才弄明白,感謝),那麼我們可以領g(n)表示有多少對(a,b)滿足a*b=n,然後對g求個首碼和f(n)就出來了。


#include<iostream>#include<algorithm>#include<cstdio>#include<vector>#include<cstring>#include<map>using namespace std;typedef long long ll;const int maxn = 1e6 + 10;const ll mod = 1007;#define rep(i,a,b) for(int i=(a);i<(b);i++)#define pb push_backll f[maxn];void init(int n){    memset(f,0,sizeof f);    for(int i = 1; i <= n; i++)        for(int j = i; j <= n; j += i)            f[j]++;    for(int j = 1; j <= n; j++) {        f[j] = (f[j]+f[j-1])%mod;    }    for(int j = 1; j <= n; j++) {        f[j] = (f[j]+f[j-1])%mod;    }}int main(){    init(1000000);    int L,R;    while(~scanf("%d%d",&L,&R)) {        printf("%d\n", (f[R]-f[L-1]+mod)%mod);    }    return 0;}



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.