A simple problem(湘大邀请赛)
A simple problem |
||
| Accepted : 61 | Submit : 418 | |
| Time Limit : 15000 MS | Memory Limit : 655360 KB | |
Problem DescriptionThere is a simple problem. Given a number N. you are going to calculate N%1+N%2+N%3+...+N%N. InputFirst line contains an integer T, there are T(1≤T≤50) cases. For each case T. The length N(1≤N≤1012). OutputOutput case number first, then the answer. Sample Input1 Sample OutputCase 1: 4 |
ps:http://202.197.224.59/OnlineJudge2/index.php/Problem/read/id/1203
#include <iostream>
#include <cstdio>
#include <cstring>
#include <climits>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <list>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <complex>
#define mp make_pair
#define X first
#define Y second
#define MEMSET(a, b) memset(a, b, sizeof(a))
using namespace std; typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vi::iterator vi_it;
typedef map<int, int> mii;
typedef priority_queue<int> pqi;
typedef priority_queue<int, vector<int>, greater<int> > rpqi;
typedef priority_queue<pii> pqp;
typedef priority_queue<pii, vector<pii>, greater<pii> > rpqp; const int MAX_N = + ;
const ll LL = ;
int a[MAX_N]; struct bigNum
{
ll bit[]; bigNum() {
} bigNum(const ll &b = ) {
bit[] = b % LL;
bit[] = b / LL;
bit[] = ;
} void format() {
bit[] += bit[] / LL;
bit[] %= LL;
bit[] += bit[] / LL;
bit[] %= LL;
} bigNum operator * (const bigNum &bg) const {
bigNum tmp();
for (int i = ; i < ; ++i) {
for (int j = ; j <= i; ++j) tmp.bit[i] += bit[j] * bg.bit[i - j];
}
tmp.format();
return tmp;
} void operator = (const bigNum &bg) {
for (int i = ; i < ; ++i) bit[i] = bg.bit[i];
} void operator *= (const bigNum &bg) {
*this = *this * bg;
} bigNum operator + (const bigNum &bg) const {
bigNum tmp();
for (int i = ; i < ; ++i) tmp.bit[i] = bit[i] + bg.bit[i];
tmp.format();
return tmp;
} void operator += (const bigNum &bg) {
*this = *this + bg;
} void half() {
if (bit[] % ) bit[] += LL;
bit[] /= ;
if (bit[] % ) bit[] += LL;
bit[] /= ;
bit[] /= ;
} void print() {
bool flag = false;
if (bit[]) printf("%I64d", bit[]), flag = true;
if (flag) printf("%09I64d", bit[]);
else if (bit[]) printf("%I64d", bit[]), flag = true;
if (flag) printf("%09I64d", bit[]);
else printf("%I64d", bit[]);
}
}; int main(int argc, char *argv[])
{
// freopen("D:\\in.txt", "r", stdin);
int t;
cin >> t;
for (int cas = ; cas <= t; ++cas) {
ll n;
scanf("%I64d", &n);
bigNum bn(n), ans();
int k = (int)sqrt((double)n);
for (int i = ; i <= k; ++i) {
bigNum tmp1(n / i - n / (i + ));
bigNum tmp2(n + n - i * (n / i + n / (i + ) + ));
tmp1 *= tmp2;
tmp1.half();
ans += tmp1;
}
ll tmp();
int lmt = (int)(n / (k + ));
for (int i = ; i <= lmt; ++i) tmp += n % i;
bigNum tt(tmp);
ans += tt;
printf("Case %d: ", cas);
ans.print();
puts("");
}
return ;
}
A simple problem(湘大邀请赛)的更多相关文章
- ACM: A Simple Problem with Integers 解题报告-线段树
A Simple Problem with Integers Time Limit:5000MS Memory Limit:131072KB 64bit IO Format:%lld & %l ...
- 【HDU 3483】 A Very Simple Problem (二项式展开+矩阵加速)
A Very Simple Problem Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Ot ...
- POJ 3468 A Simple Problem with Integers(分块入门)
题目链接:http://poj.org/problem?id=3468 A Simple Problem with Integers Time Limit: 5000MS Memory Limit ...
- hdu3483 A Very Simple Problem 非线性递推方程2 矩阵快速幂
题目传送门 题目描述:给出n,x,mod.求s[n]. s[n]=s[n-1]+(x^n)*(n^x)%mod; 思路:这道题是hdu5950的进阶版.大家可以看这篇博客hdu5950题解. 由于n很 ...
- 牛客NC15879 A Simple Problem
传送门:A Simple Problem 题意 给定两个序列s1和s2,同样的数字可以用相同的别的数字代替(并且也可以是出现过的数字),问s2在s1中出现了几次. 题解 首先预处理一下这两个序列,因为 ...
- hihoCoder 1427 : What a Simple Research(大㵘研究)
hihoCoder #1427 : What a Simple Research(大㵘研究) 时间限制:1000ms 单点时限:1000ms 内存限制:256MB Description - 题目描述 ...
- POJ 3468 A Simple Problem with Integers(线段树 成段增减+区间求和)
A Simple Problem with Integers [题目链接]A Simple Problem with Integers [题目类型]线段树 成段增减+区间求和 &题解: 线段树 ...
- POJ 3468 A Simple Problem with Integers(线段树/区间更新)
题目链接: 传送门 A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Description Yo ...
- poj 3468:A Simple Problem with Integers(线段树,区间修改求和)
A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 58269 ...
随机推荐
- 段的性能统计信息v$segment_statistics
v$segment_statistics视图记录了段的统计信息 简单的几个字段就不说了,就说最后三个吧 STATISTIC_NAME,STATISTIC#,VALUE记录了发生在表上的操作 SYS @ ...
- 查看 Oracle 数据库锁和解锁的方法
-- 查看数据库锁明细 select a.sid, b.serial#, b.username, b.osuser, b.machine, b.program, c.object_name,d.spi ...
- JavaScript视频分享,学无止境。
http://blog.sina.com.cn/s/blog_735ed39a0102voy3.html
- web browser 发展史
浏览器是指可以显示网页服务器或者文件系统的HTML文件(标准通用标记语言的一个应用)内容,用来显示在万维网或局域网等内的文字.图像及其他信息,便于人们的浏览. Tim Berners-Lee是第一个使 ...
- 手工检测SQL注入漏洞
SQL注入,就是通过把SQL命令插入到Web表单提交或输入域名或页面请求的查询字符串,最终达到欺骗服务器执行恶意的SQL命令,具体来说,它是利用现有应用程序将(恶意的)SQL命令注入到后台数据库引擎执 ...
- 性能瓶颈之Target
最常见的性能问题都发生在向目标数据库写数据的时候 常见的与目标数据库性能有关的问题有: 1) 数据库的checkpoint间隔太小 2) 数据库网络包太小 3) 在进行大批量数据加载时的问题 ...
- 如何将云原生工作负载映射到 Kubernetes 中的控制器
作者:Janakiram MSV 译者:殷龙飞 原文地址:https://thenewstack.io/how-to-map-cloud-native-workloads-to-kubernetes- ...
- Linux编程 24 shell编程(结构化 if [ condition ] 数值比较,字符串比较)
一.概述 接着上篇讲的结构化命令,最后讲到了test命令的另一种写法 if [ condition ],它的语法格式如下: --格式如下: if [ condition ] then commands ...
- Android--解析XML之DOM
前言 前面已经介绍了Android平台下两种解析XML的方法,SAX和PULL,这两个均为事件驱动,以流的形式解析XML文档.现在介绍一种新的方式DOM方式解析XML. DOM是一种用于XML文档对象 ...
- HttpContextAccessor不会出现线程同步问题?
我有一段比较常规的.net core mvc代码,就是StartUp函数中注册HttpContextAccessor到系统DI工厂中,如图: 然后调用方是service层,这个service层是使用a ...