湖南省第十二屆大學生電腦程式設計競賽 problem A 2016

來源:互聯網
上載者:User

標籤:

如果 a * b % 2016 == 0

如果a = 1 ,且 a * b % 2016 == 0

考慮一下a = 2017的時候

2017 * b = (2016 + 1) * b % 2016 == 0必定成立

那麼就是說1中搭配成的b,2017一樣能搭配。

同樣:4033 * b = (2016 + 2016 + 1) * b % 2016 == 0必定成立

所以,我可以枚舉[1,2016]中[1,2016]中,i * j % 2016 == 0的對數,然後乘上對應的[1,n]中有i這個數的個數,代替數也算,代替數就是那些等價數,1 --- 2017 --- 4033 

#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <algorithm>using namespace std;#define inf (0x3f3f3f3f)typedef long long int LL;#include <iostream>#include <sstream>#include <vector>#include <set>#include <map>#include <queue>#include <string>LL n, m;const int maxn = 2016 + 20;LL numn[maxn], numm[maxn];void work () {   LL tnk = n / 2016;   LL rn =  n % 2016;   memset (numn, 0, sizeof numn);   memset (numm, 0, sizeof numm);   for (int i = 1; i <= rn; ++i) {       numn[i] = tnk + 1;   }   for (int i = rn + 1; i <= 2016; ++i) {       numn[i] = tnk;   }   LL tmk = m / 2016;   LL rm = m % 2016;   for (int i = 1; i <= rm; ++i) {       numm[i] = tmk + 1;   }   for (int i = rm + 1; i <= 2016; ++i) {       numm[i] = tmk;   }   LL ans = 0;   for (int i = 1; i <= 2016; ++i) {       for (int j = 1; j <= 2016; ++j) {           if ((i * j) % 2016 == 0) {               ans += numn[i] * numm[j];           }       }   }   cout << ans << endl;}int main () {#ifdef local    freopen("data.txt","r",stdin);#endif    while (cin >> n >> m) {        work ();    }    return 0;}
View Code

 

湖南省第十二屆大學生電腦程式設計競賽 problem A 2016

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.