BUPT OJ181 T-Residual Set

2023-10-28 22:33
文章标签 set residual bupt oj181

本文主要是介绍BUPT OJ181 T-Residual Set,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

题目描述

Given a pair of number (p,t) where p is a prime and t is a non-negative integer.
The 'Residual Set' of any prime number p is all the integers between 1 and p-1,
that is, '1 2 3 4 ... p-2 p-1'.
What's more, a 'T-Residual Set' of any prime number p means the set of integers below:
'1^T%p 2^T%p 3^T%p 4^T%p ... (p-2)^T%p (p-1)^T%p', where T must be non-negative.
Now for each pair of (p,t), you should calculate how many distinct numbers there are in the  't-Residual Set' of p.

输入格式

A number  T(T<=106)  in first line.
Then T test cases follow.
Each Test case contains two number p (0<p<10^8) and t (0<t<2^31),
which meanings areaccording to the description.

输出格式

Output T lines.
Each line contains one number, refers to the answer.
Sample Input

输入样例

3
7 9
17 89
47 56

输出样例

2
16
23

热身赛哪一题来着...已经忘记了= = 蛮有趣的数学题, 解法是推公式 

明明组里的大神做出来了结果在比赛快结束的时候居然提交错题目了...嗯, 所以说这题本来也不应该算是我做出来的吧

后来自己还是重新推了一遍, 感觉还好= =



/*
USER_ID: test#birdstorm
PROBLEM: 181
SUBMISSION_TIME: 2014-03-08 01:05:06
*/
#include<stdio.h>
#include<stdlib.h>int GCD(int a,int b)
{int n=a%b;while(n){a=b; b=n;n=a%b;}return b;
}main()
{int T,p,t;scanf("%d",&T);while(T--){scanf("%d%d",&p,&t);printf("%d\n",(p-1)/GCD(t,p-1));}return 0;
}


这篇关于BUPT OJ181 T-Residual Set的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/296407

相关文章

poj 3050 dfs + set的妙用

题意: 给一个5x5的矩阵,求由多少个由连续6个元素组成的不一样的字符的个数。 解析: dfs + set去重搞定。 代码: #include <iostream>#include <cstdio>#include <set>#include <cstdlib>#include <algorithm>#include <cstring>#include <cm

Collection List Set Map的区别和联系

Collection List Set Map的区别和联系 这些都代表了Java中的集合,这里主要从其元素是否有序,是否可重复来进行区别记忆,以便恰当地使用,当然还存在同步方面的差异,见上一篇相关文章。 有序否 允许元素重复否 Collection 否 是 List 是 是 Set AbstractSet 否

论文翻译:ICLR-2024 PROVING TEST SET CONTAMINATION IN BLACK BOX LANGUAGE MODELS

PROVING TEST SET CONTAMINATION IN BLACK BOX LANGUAGE MODELS https://openreview.net/forum?id=KS8mIvetg2 验证测试集污染在黑盒语言模型中 文章目录 验证测试集污染在黑盒语言模型中摘要1 引言 摘要 大型语言模型是在大量互联网数据上训练的,这引发了人们的担忧和猜测,即它们可能已

多路转接之select(fd_set介绍,参数详细介绍),实现非阻塞式网络通信

目录 多路转接之select 引入 介绍 fd_set 函数原型 nfds readfds / writefds / exceptfds readfds  总结  fd_set操作接口  timeout timevalue 结构体 传入值 返回值 代码 注意点 -- 调用函数 select的参数填充  获取新连接 注意点 -- 通信时的调用函数 添加新fd到

Android set Tag, findViewWithTag使用

设置了tag为“principal”的view ImageView principal = (ImageView) findViewById(R.id.imagen_home_0);principal.setTag("principal"); 在其它地方获取,获取已经设置了tag为“principal”的view LayoutInflater inflater = LayoutInflate

C++ STL关联容器Set与集合论入门

1. 简介 Set(集合)属于关联式容器,也是STL中最实用的容器,关联式容器依据特定的排序准则,自动为其元素排序。Set集合的底层使用一颗红黑树,其属于一种非线性的数据结构,每一次插入数据都会自动进行排序,注意,不是需要排序时再排序,而是每一次插入数据的时候其都会自动进行排序。因此,Set中的元素总是顺序的。 Set的性质有:数据自动进行排序且数据唯一,是一种集合元素,允许进行数学上的集合相

Eclipse或MyEclipse中Java Working Set管理项目

随着学习JAVA的时间的越来越久,项目也越来越多,Eclipse或MyEclipse界面中显示一堆! 每次工作使用到的项目肯定不会太多...... 每次从这么大数量的工程当中找到自己要使用的, 必须大规模的滚动滚动条...... 图片一   Project Explorer中:    图片二:Package Explorer中: 这样就好找很多了,分类放!

STL set整理

#include<set>#include<cstdio>#include<iterator>#include<iostream>#include<algorithm>using namespace std;//set 集合的操作//multisetset<int>Set1;set<int>Set2;set<int>Set3;/*begin() 返回指向第一个元素的迭代器

解决PHP Warning: strftime(): It is not safe to rely on the system's timezone set

当运行一些程序时,在httpd日志中会有如下警告日志: PHP Warning:  strftime(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set(

Java中集合类Set、List和Map的区别

Java中的集合包括三大类,它们是Set、List和Map,它们都处于java.util包中,Set、List和Map都是接口,它们有各自的实现类。Set的实现类主要有HashSet和TreeSet,List的实现类主要有ArrayList,Map的实现类主要有HashMap和TreeMap。那么它们有什么区别呢? Set中的对象不按特定方式排序,并且没有重复对象。但它的有些实现类能对集合中的对