标签:
大水题,计算出below n内是3,5倍数的总和
数据较大,只能用求和公式
#include <iostream> #include <cstdio> typedef long long ll; using namespace std; int main() { int T; scanf("%d",&T); while(T--){ int n; scanf("%d",&n); ll sum=0; ll p; p = (n-1)/3; sum += (1LL)*3*(p+1)*p/2; p = (n-1)/5; sum += (1LL)*5*(p+1)*p/2; p = (n-1)/15; sum -= (1LL)*15*(p+1)*p/2; cout<<sum<<endl; } //cout << "Hello world!" << endl; return 0; }
标签:
原文地址:http://www.cnblogs.com/EdsonLin/p/5702123.html