ACM-ICPC 2018 南京赛区网络预赛(A, J)
A 签到题
Alice, a student of grade 666, is thinking about an Olympian Math problem, but she feels so despair that she cries. And her classmate, Bob, has no idea about the problem. Thus he wants you to help him. The problem is:
We denote k!k!k!:
k!=1×2×⋯×(k−1)×kk! = 1 \times 2 \times \cdots \times (k - 1) \times kk!=1×2×⋯×(k−1)×k
We denote SSS:
S=1×1!+2×2!+⋯+S = 1 \times 1! + 2 \times 2! + \cdots +S=1×1!+2×2!+⋯+
(n−1)×(n−1)! (n - 1) \times (n-1)!(n−1)×(n−1)!
Then SSS module nnn is ____________
You are given an integer nnn.
You have to calculate SSS modulo nnn.
Input
The first line contains an integer T(T≤1000)T(T \le 1000)T(T≤1000), denoting the number of test cases.
For each test case, there is a line which has an integer nnn.
It is guaranteed that 2≤n≤10182 \le n\le 10^{18}2≤n≤1018.
Output
For each test case, print an integer SSS modulo nnn.
Hint
The first test is: S=1×1!=1S = 1\times 1!= 1S=1×1!=1, and 111 modulo 222 is 111.
The second test is: S=1×1!+2×2!=5S = 1\times 1!+2 \times 2!= 5S=1×1!+2×2!=5 , and 555 modulo 333 is 222.
打个表就会发现结果等于 N-1;直接输出就是了;
F
题目链接 :https://nanti.jisuanke.com/t/30999
思路 : 欧筛 + 打表 ,水过的
#include<cstring>
#include<iostream>
#include<cstdio>
#include<ctime>
using namespace std;
#define N 20000005
#define ll long long
int vis[N];
int p[N], cnt, v[N];
ll sum[N];
void init(){
int i, j, k;
sum[]= ;
for(i = ; i < N; ++i){
sum[i] = sum[i-]+vis[i]; // sum[i] 就是答案
if (v[i]== ){
p[cnt++] = i;
}
for (j = ; j < cnt && i * p[j] < N; j++){
ll ans = p[j]*p[j];
if(i%p[j]) {vis[i*p[j]] = vis[i]*; v[i*p[j]] =;}
if(i%ans == ) {vis[i*p[j]] =; v[i*p[j]] =;break;} // 如果i含有至少两个相同的素数, 将 vis[i*p[j]] 置0;
if(i%p[j]==){vis[i*p[j]] = vis[i]/; v[i*p[j]] =;break;}
}
}
} int main()
{
vis[] = ;
for(int i = ; i < N; i++)
{
vis[i] = ;
}
init();
int t;
cin >> t;
while(t--)
{
int n;
cin >> n;
cout << sum[n] << endl;
/* for(int i = 1; i <= 300; i++)
{
cout << "vis " << i <<" : " << vis[i] << endl;
cout << "sum "<< i << " : " << sum[i] << endl; } */ }
}
ACM-ICPC 2018 南京赛区网络预赛(A, J)的更多相关文章
- ACM-ICPC 2018 南京赛区网络预赛 J.sum
A square-free integer is an integer which is indivisible by any square number except 11. For example ...
- ACM-ICPC 2018 南京赛区网络预赛 E题
ACM-ICPC 2018 南京赛区网络预赛 E题 题目链接: https://nanti.jisuanke.com/t/30994 Dlsj is competing in a contest wi ...
- ACM-ICPC 2018 南京赛区网络预赛B
题目链接:https://nanti.jisuanke.com/t/30991 Feeling hungry, a cute hamster decides to order some take-aw ...
- 计蒜客 30999.Sum-筛无平方因数的数 (ACM-ICPC 2018 南京赛区网络预赛 J)
J. Sum 26.87% 1000ms 512000K A square-free integer is an integer which is indivisible by any squar ...
- 计蒜客 30996.Lpl and Energy-saving Lamps-线段树(区间满足条件最靠左的值) (ACM-ICPC 2018 南京赛区网络预赛 G)
G. Lpl and Energy-saving Lamps 42.07% 1000ms 65536K During tea-drinking, princess, amongst other t ...
- 计蒜客 30990.An Olympian Math Problem-数学公式题 (ACM-ICPC 2018 南京赛区网络预赛 A)
A. An Olympian Math Problem 54.28% 1000ms 65536K Alice, a student of grade 66, is thinking about a ...
- ACM-ICPC 2018 南京赛区网络预赛 B. The writing on the wall
题目链接:https://nanti.jisuanke.com/t/30991 2000ms 262144K Feeling hungry, a cute hamster decides to o ...
- ACM-ICPC 2018 南京赛区网络预赛
轻轻松松也能拿到区域赛名额,CCPC真的好难 An Olympian Math Problem 问答 只看题面 54.76% 1000ms 65536K Alice, a student of g ...
- ACM-ICPC 2018 南京赛区网络预赛 L. Magical Girl Haze
262144K There are NN cities in the country, and MM directional roads from uu to v(1\le u, v\le n)v ...
- ACM-ICPC 2018 南京赛区网络预赛(12/12)
ACM-ICPC 2018 南京赛区网络预赛 A. An Olympian Math Problem 计算\(\sum_{i=1}^{n-1}i\cdot i!(MOD\ n)\) \(\sum_{i ...
随机推荐
- react-native run-android时 SDK location not found.报错
报错 原因 缺少local.properties文件(SDK location) 解决 方法一:在android Studio中打开项目android目录,会自动创建local.properties文 ...
- 【并查集缩点+tarjan无向图求桥】Where are you @牛客练习赛32 D
目录 [并查集缩点+tarjan无向图求桥]Where are you @牛客练习赛32 D PROBLEM SOLUTION CODE [并查集缩点+tarjan无向图求桥]Where are yo ...
- javaweb 与jsp页面的交互流程 (初次接触时写)
javaweb 与jsp页面的交互流程 javaweb项目目录 1. javaweb项目的一般目录: 2. jsp 页面一般情况下放在 top(前台页面) back(后台页面) 3. 后台代码 放在s ...
- 【函数式编程】reducer为什么叫reducer
最近学习前端的技术,在了解react对DOM的组件抽象,但不提供整体的组件通讯时候,了解了redux,然后就是react-redux: 抽象后,视图完全由对象决定,而用户只能接触视图,所以对象的改变必 ...
- 正则序RegExp
正则的理解 1.正则的懒惰性 每次在exec()中捕获的时候,只捕获第一次匹配的内容,而不往下不捕获了.我们把这叫正则的懒惰性,每一次捕获的开始位置都是从0开始 解决正则的懒惰性 修饰符g 正则 ...
- jenkins测试配置
- ApiShell
using System; using System.Runtime.InteropServices; using HWND = System.IntPtr; using HANDLE = Syste ...
- 终于明白了 C# 中 Task.Yield 的用途
最近在阅读 .NET Threadpool starvation, and how queuing makes it worse 这篇博文时发现文中代码中的一种 Task 用法之前从未见过,在网上看了 ...
- centos7最小化安装系统
https://blog.csdn.net/hellboy0621/article/details/80392273
- STM32 内部flash的读写程序
/* Base address of the Flash sectors */ #define ADDR_FLASH_SECTOR_0 ((uint32_t)0x08000000) /* Base ...