sacgajcvs

Untitled

Dec 23rd, 2019
356
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1.  
  2. #include <stdio.h>
  3. #include <math.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <string>
  7. #include <iostream>
  8. #include <algorithm>
  9. #include <ctype.h>
  10. #include <set>
  11. #include <map>
  12. #include <vector>
  13. #include <stack>
  14. #include <queue>
  15. #define left (now<<1)
  16. #define right ((now<<1)+1)
  17. #define mid ((l+r)>>1)
  18. #define fst first
  19. #define snd second
  20. #define sfn scanf("%d",&n)
  21. #define sfnm scanf("%d%d",&n,&m)
  22. #define sft scanf("%d",&t)
  23. #define pfans printf("%d\n",ans)
  24. using namespace std;
  25. typedef long long lint;
  26.  
  27. lint a,b,n,t;
  28. vector<lint> sushu;
  29.  
  30. void getFac(lint n){ //求n的所有素因数
  31. sushu.clear();
  32. for(int i = 2; i * i <= n; ++i){
  33. if(n % i == 0){
  34. sushu.push_back(i);
  35. while(n % i == 0){ n /= i;}
  36. }
  37. }
  38. if(n > 1){
  39. sushu.push_back(n);
  40. }
  41. }
  42.  
  43. lint getNum(lint n){ //求1-n有多少数字和k不互素
  44. lint len = 1 << sushu.size();
  45. lint re = 0;
  46. if(n == 0){ return 0;}
  47. for(int i = 1; i < len; ++i){
  48. lint sum = 0;
  49. lint now = 1;
  50. for(int j = 0; j < sushu.size(); ++j){
  51. if((1<<(j))&i){
  52. ++sum; now *= sushu[j];
  53. }
  54. }
  55. sum&1?re+=n/now:re-=n/now;
  56. }
  57. return re;
  58. }
  59.  
  60. int main(){
  61. scanf("%I64d",&t);
  62. int ca = 0;
  63. while(t--){
  64. ++ca;
  65. scanf("%I64d%I64d%I64d",&a,&b,&n);
  66. getFac(n);
  67. lint ansa = a - 1 - getNum(a - 1);
  68. lint ansb = b - getNum(b);
  69. lint ans = ansb - ansa;
  70. printf("Case #%d: %I64d\n",ca,ans);
  71. }
  72. return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment