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; } */ }
}

大佬博客   : http://www.cnblogs.com/Dup4/p/9570883.html

ACM-ICPC 2018 南京赛区网络预赛(A, J)的更多相关文章

  1. ACM-ICPC 2018 南京赛区网络预赛 J.sum

    A square-free integer is an integer which is indivisible by any square number except 11. For example ...

  2. ACM-ICPC 2018 南京赛区网络预赛 E题

    ACM-ICPC 2018 南京赛区网络预赛 E题 题目链接: https://nanti.jisuanke.com/t/30994 Dlsj is competing in a contest wi ...

  3. ACM-ICPC 2018 南京赛区网络预赛B

    题目链接:https://nanti.jisuanke.com/t/30991 Feeling hungry, a cute hamster decides to order some take-aw ...

  4. 计蒜客 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 ...

  5. 计蒜客 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 ...

  6. 计蒜客 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 ...

  7. 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 ...

  8. ACM-ICPC 2018 南京赛区网络预赛

    轻轻松松也能拿到区域赛名额,CCPC真的好难 An Olympian Math Problem 问答 只看题面 54.76% 1000ms 65536K   Alice, a student of g ...

  9. 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 ...

  10. 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 ...

随机推荐

  1. SpringCloud教程 | 第三篇: 服务消费者(Feign)

    上一篇文章,讲述了如何通过RestTemplate+Ribbon去消费服务,这篇文章主要讲述如何通过Feign去消费服务.一.Feign简介 Feign是一个声明式的伪Http客户端,它使得写Http ...

  2. python 将list的值赋值给变量

    list中有n个值,赋值给k个变量:a1, a2, ……,ak n = k时:a1, a2, ……,ak = list n > k时:使用1式报错:ValueError: too many va ...

  3. Android Frameworks的base目录内容分析 “Android Frameworks base”

    Framework文件夹中base目录下文件分类: Android系统结构框架: Android Framework层各文件夹功能分类:

  4. asp 获取url 返回值 和 对json 返回值的处理

    Function GetHttpPage(HttpUrl,endoce) If endoce = "" Then endoce = "GB2312" If Is ...

  5. react-native run-android时 SDK location not found.报错

    报错 原因 缺少local.properties文件(SDK location) 解决 方法一:在android Studio中打开项目android目录,会自动创建local.properties文 ...

  6. MAC下 mySQL及workbench安装

    1.首先去mysql 网站下载安装包,https://dev.mysql.com/downloads/mysql/ 选择第一个.dmg格式的下载安装 2.安装完成后,在System Preferenc ...

  7. JDBC API 事务的实践

    使用了持久化框架几乎没有使用过原生的jdbc API ,发现原来使用jdbc API来实现事务也是很简单的. 数据库的链接connection具有一个属性autocommit,这个属性默认是true, ...

  8. sql的基础用法

    # sql 对大小写不敏感 # 查询表中的所有信息 select * from `Customers`; # 查询指定字段 CustomerName,Country select CustomerNa ...

  9. Nginx负载均衡后端健康检查(支持HTTP和TCP)

    之前有一篇文章记录nginx负载均衡后端检查,链接为 https://www.cnblogs.com/minseo/p/9511456.html 但是只包含http健康检查不包含tcp下面安装ngin ...

  10. 电子产品使用感受之----AirPods的一天使用体验分享

    2019.03.29 晚上8点50分更新: 3月28日我的新款AirPods终于到货了,作为一代产品使用2年的用户,终于可以说说这枚新品的一天使用感受了: 我们会从以下几个方面来进行阐述: 外观 技术 ...